square recursive

PHOTO EMBED

Sat Jun 26 2021 22:09:34 GMT+0000 (Coordinated Universal Time)

Saved by @1nshed #java

/**
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;
   }		
}
content_copyCOPY