how to write a program to find the “sum of the squares” of the numbers from 1 to 100 in java
I would write a loop that starts at x = 1 Then adds x squared to a variable (maybe called 'total') Next you just let the loop run to x <= 100.
I may have misread your question. If you meant the square root of the numbers 1 - 100 I would just substitute "Then adds x squared" with "Then add the square root of x to a variable..."
It cud be done using for loop,following code will print the Sum of squares :) , if ya ll get some problem executing this code , ask it out and if it works, keep me posted :) int sum = 0; for (int i =1;i<100;i++) { sum = sum + (i*i*) ; //this will print squares between 1-100 System.out.println("Sum of the sqaures is:"sum); }
please not that u gotta change the condition to i<=100 i have made a typo there and written it as i <100, so updated code is here :== int sum = 0; for (int i =1;i<=100;i++) { sum = sum + (i*i*) ; //this will print squares between 1-100 System.out.println("Sum of the sqaures is:"sum); }
Join our real-time social learning platform and learn together with your friends!