Exercises

  1. 16.3 (Comparing Strings) Write an application that uses String method compareTo to compare two strings input by the user. Output whether the first string is less than, equal to or greater than the second.

  2. 16.4 (Comparing Portions of Strings) Write an application that uses String method region-Matches to compare two strings input by the user. The application should input the number of characters to be compared and the starting index of the comparison. The application should state whether the strings are equal. Ignore the case of the characters when performing the comparison.

  3. 16.5 (Random Sentences) Write an application that uses random-number generation to create sentences. Use four arrays of strings called article, noun, ...

Get Java How to Program (early objects), 9/e now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.