Java program that uses a loop to compute the sum of all squares between 1 and 100 (inclusive)
Posted by Samath
Last Updated: April 03, 2022

Write a Java program that uses a loop to compute the sum of all squares between 1 and 100 (inclusive).

Code:

import java.util.Scanner;

public class Main
{
	public static void main(String[] args) {
	    
	   double total = 0;
	    for (int i = 1; i < 101; i++) {
	        total += i * i;	    
	    }
	        System.out.println("Result: " + total);
	}
}