Java - Get the sum of square using an array

Description

Get the sum of square using an array

Demo

import java.util.Scanner;


public class SumSquare {
     public static void main(String[] args) {
          Scanner input = new Scanner(System.in);

          System.out.print("Please enter the max number:");
          int max = input.nextInt();
          //from  w  ww.ja  v  a  2s  .c o m
          int i;
          int sq;
          int sqsum = 0;
          
          for (i = 1; i <= max; ++i) {
               sq = i*i;
               System.out.println("Number " + i + " squared is " + sq);
               sqsum += sq;
          }
          System.out.println("Sum of squares is " + sqsum);
     }

}

Related Topic