Fill in the blanks so that the program prints out every element, in order.

A good answer might be:

class countArray
{

  public static void main ( String[] args )
  {
    int[] egArray = { 2, 4, 6, 8, 10, 1, 3, 5, 7, 9 };

    for ( int index= 0 ; index < 10 ; index++ )
    {
      System.out.println( egArray[ index ] );
    }
  }
}

The length of an Array

It is annoying to have to count how many elements there are in an array. Worse, this might not be known when the program is being written. Array objects are created as the program is running and can be created with any number of elements. It is essential, sometimes, to write a program that can deal with an array who's size is not known until the program is running.

This can be done by asking the array how many elements it has. Remember that an array is an object. As an object, it has more in it than just the slots. An array object has a member length that is the number of slots (number of elements) it has. The for statement can be written like this:

    for ( int index= 0 ; index < egArray.length; index++ )

Lines of code similar to the above are very common in programs. One dimensional arrays are very common. Usually a program will use many of them. Almost always a program will "visit" each element of an array using a for loop such as the above.

QUESTION 3:

Fill in the blanks in this line of code so that the elements of the array are visited from the last element down to element 0:

for ( int index= ___________ ; ________________ ; _____________ )

Click Here after you have answered the question