write a program in Java to find the sum of the given series 1 + 4 + 9 + 16 + 25
vanshika1393:
Anyone know the answer?
Answers
Answered by
1
public class SquareSum {
... public static void main(String[] args) {
... ... int sum = 0; // declare sum, initialise to zero
... ... for (int i=1; i<=10; i++) { // loop ten times
... ... ... sum += i * i; // add square of loop value to sum
... ... } // for
... ... System.out.println("Sum = " + sum);
... } // main()
} // class
// Note: I've used "..." to indicate a tab character (as Y!Answers removes indentation)
... public static void main(String[] args) {
... ... int sum = 0; // declare sum, initialise to zero
... ... for (int i=1; i<=10; i++) { // loop ten times
... ... ... sum += i * i; // add square of loop value to sum
... ... } // for
... ... System.out.println("Sum = " + sum);
... } // main()
} // class
// Note: I've used "..." to indicate a tab character (as Y!Answers removes indentation)
Similar questions