Java - Use for loop, while loop and do while loop to calculate sum of squares

Description

Use for loop, while loop and do while loop to calculate sum of squares

Demo

import java.util.Scanner;

public class SumSquareArr {
     public static void main(String[] args) {
          int max = 10;

          int[]arr1 = new int[max+1];
          int[]arr2 = new int[max+1];
          int[]arr3 = new int[max+1];

          int i = 1;

          // For-loop to calculate 
          for (i = 1;i <= max;i++)
               arr1[i] = arr1[i-1] + i*i;

          i = 1;//from   w ww  .j  a v  a  2  s .com
          
          // While-loop to calculate
          while (i <= max) {
               arr2[i] = arr2[i-1] + i*i;
               i++;
          }

          i = 1;

          // Do-While-loop to calculate
          do
               arr3[i] = arr3[i-1] + i*i;
          while (++i <= max);

          for (i = 0; i <= max; i++)
               System.out.println("Arr1 " + arr1[i] + " Arr2 " + arr2[i] + " Arr3 " + arr3[i]);

          System.out.println("Sum of squares is " + arr1[max]);
                    
     }
}