The sum of all squares between 1 and 100 inclusive?

If you want to do it in your way I mean first square the value of each number,keep it in a variable and add it to the sum you can use a different variable instead of n to store the square value of each number like this :

int n = 1;
int squareValue;
int sum = 0;
while (n <= 10) {

    squareValue= (n*n);

    sum += squareValue; 

    n++;
}
System.out.println(sum);

Leave a Comment

tech