Source of InitArray.java


  1: // Fig. 7.3: InitArray.java
  2: // Initializing the elements of an array with an array initializer.
  3: 
  4: public class InitArray 
  5: {
  6:    public static void main( String args[] )
  7:    {
  8:       // initializer list specifies the value for each element
  9:       int array[] = { 32, 27, 64, 18, 95, 14, 90, 70, 60, 37 };
 10: 
 11:       System.out.printf( "%s%8s\n", "Index", "Value" ); // column headings
 12:    
 13:       // output each array element's value 
 14:       for ( int counter = 0; counter < array.length; counter++ )
 15:          System.out.printf( "%5d%8d\n", counter, array[ counter ] );
 16:    } // end main
 17: } // end class InitArray
 18: 
 19: 
 20: /**************************************************************************
 21:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 22:  * Pearson Education, Inc. All Rights Reserved.                           *
 23:  *                                                                        *
 24:  * DISCLAIMER: The authors and publisher of this book have used their     *
 25:  * best efforts in preparing the book. These efforts include the          *
 26:  * development, research, and testing of the theories and programs        *
 27:  * to determine their effectiveness. The authors and publisher make       *
 28:  * no warranty of any kind, expressed or implied, with regard to these    *
 29:  * programs or to the documentation contained in these books. The authors *
 30:  * and publisher shall not be liable in any event for incidental or       *
 31:  * consequential damages in connection with, or arising out of, the       *
 32:  * furnishing, performance, or use of these programs.                     *
 33:  *************************************************************************/