Tail of a Substring

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:

0

Tail of a Substring

Here is a fragment that computes the tail of the example string, starting with the first "a":

String example = "The sea is calm to-night." ;
String tail = example.substring( example.indexOf( "a" ) );

The way this works is:

Computing a Substring

indexOf() and substring() can be used to chop a string into useful pieces. Here is a fragment that chops an assignment statment into the part to the left of the assignment operator and the part to the right:

String statement = "value = alpha*beta + gamma;"  ;

int loc = statement.indexOf( "=" );
if ( loc !=  )
{
  String left = statement.substring(  0,  );
  String right = statement.substring(  + 1 );
}

QUESTION 11:

Ooops. The fragment is not completed. Fill in the blanks.