InitArray.java

C:\jhtp_10th\ch07\fig07_03>java InitArray
Index   Value
    0      32
    1      27
    2      64
    3      18
    4      95
    5      14
    6      90
    7      70
    8      60
    9      37


InitArray.java

// Fig. 7.3: InitArray.java
// Initializing the elements of an array with an array initializer.

public class InitArray 
{
   public static void main(String[] args)
   {
      // initializer list specifies the initial value for each element
      int[] array = {32, 27, 64, 18, 95, 14, 90, 70, 60, 37};

      System.out.printf("%s%8s%n", "Index", "Value"); // column headings
   
      // output each array element's value 
      for (int counter = 0; counter < array.length; counter++)
         System.out.printf("%5d%8d%n", counter, array[counter]);
   }
} // end class InitArray


Maintained by John Loomis, updated Tue Jan 24 15:35:45 2017