Computer Science, asked by vanshika1393, 1 year ago

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 pushpa2devgmailcom
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)

vanshika1393: What?
Similar questions