The variable data is not really needed in this program. Mentally change the program so that this variable is not used.

A good answer might be:

The two lines:

      data           = Integer.parseInt( inData.readLine() );
      array[ index ] = data ;
can be replaced by the single line:
       array[ index ] = Integer.parseInt( inData.readLine() );
And then the declaration int data; should be removed.

Array Length Determined when the Program Runs

Because an array object is constructed as the program runs, its size can determined at run time. Here is the previous example, with some modifications:

import java.io.* ;

class inputArray
{

  public static void main ( String[] args ) throws IOException
  {
    BufferedReader inData = new BufferedReader ( new InputStreamReader( System.in ) );
    int[] array;
 
    // determine the array size and construct the array
    System.out.println( "What length is the array?" );
    int size  = Integer.parseInt( inData.readLine() );

    array     = new int[ _____________ ]; 

    // input the data
    for ( int index=0; index < array.length; index++)
    {
      System.out.println( "enter an integer: " );
      array[ index ] = Integer.parseInt( inData.readLine() );
    }
      
    // write out the data
    for ( int index=0; index < array.length; index++ )
    {
      System.out.println( "array[ " + index + " ] = " + array[ index ] );
    }

  }
}      

QUESTION 6:

Fill in the blank.

Click Here after you have answered the question