package sumofsquares;
import java.util.Scanner;
public class SumOfSquares {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = input.nextInt();
int sum = 0;
for (int i = 1; i <= n; i++) {
sum += i * i;
}
System.out.println("Sum of squares: " + sum);
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter