Question 2)
Write a Program to find the squares of the summation of n numbers.
Answer:-
import java.util.Scanner;
class SquareSum {
public static void main(String[] args) {
Scanner ss = new Scanner(System.in);
System.out.println("Enter any number :");
int number = ss.nextInt();
int sumation = (number * (number+1) * (2*number +1))/6;
System.out.println("The square of sum of " + number + " natural numbers is = " + sumation);
}
}
0 Comments