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