Writing a String to the Monitor

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

String[] strArray = new String[8] ;  // combined statement

. . . .

strArray[ strArray.length-1 ] = "the end" ;

Writing a String to the Monitor

Here is a fragment that writes out the first two Strings to the monitor:

System.out.println( "cell 0: " + strArray[0] );
System.out.println( "cell 1: " + strArray[1] );

Nothing unusual here. Each array cell contains a String reference that can be used in the usual ways. Here is a fragment that writes each cell's String (if there is one) to the monitor :

String[] strArray = new String[8] ;  // combined statement

. . . . .
for (int j=0; j   strArray.length; j++ )
{
  if ( strArray[j] !=  )
    System.out.println( "cell " + j + ": " + strArray[j] );
  else
    System.out.println( "cell " + j + ": " + "empty" );
}

QUESTION 6:

Fill in the blanks.