January 2014
Intermediate to advanced
736 pages
70h 43m
English
The application in Fig. E.4 creates a 10-element array and assigns to each element one of the even integers from 2 to 20 (2, 4, 6,..., 20). Then the application displays the array in tabular format. The for statement at lines 12–13 calculates an array element’s value by multiplying the current value of the control variable counter by 2, then adding 2.
1 // Fig. E.4: InitArray.java 2 // Calculating the values to be placed into the elements of an array. 3 4 public class InitArray 5 { 6 public static void main( String[] args ) 7 { 8 final int ARRAY_LENGTH = 10; // declare constant 9 int[] array = new int[ ARRAY_LENGTH ]; // create ...
Read now
Unlock full access