Answer to Question #229769 in Java | JSP | JSF for kam

Question #229769

Using a while loop, write a program to calculate and print the sum of a given number of squares.


1
Expert's answer
2021-08-25T17:32:37-0400
import java.util.Scanner;
public class Main
{
 
 public static void main(String[] args) {
    Scanner in=new Scanner(System.in);
    int n;
    int sum=0;
    int i=1;
    System.out.println("Enter n: ");
    n=in.nextInt();
    while(i<=n)
    {
        sum=sum+i*i;
        i++;
    }
    System.out.println("Sum of squares of numbers from 1 to n is : "+sum);
 }
 
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS