/** Precondition: n>=1 Returns the sum of the squares of the numbers 1 through n. */ public static int squares(int n) { if(n<1) { return 1; } else { sum+=Math.pow(n, 2); squares(n-1); return sum; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter