Source of InitArray.java


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