ITEC 120 LAB 6 Back to Lab index page

String and Random methods

Write a Java program that will use methods from the java.lang.String class and from the java.util.Random class.

First, your program will ask the user to input a String.

Next, your program will display the original string (surrounded by "s), the length of the string, the first character in the string, and the last character in the string. Next, randomly generate two positions and display the positions along with the characters at those positions.

Sample run:
Program displays:

Please type a string:

User enters: How about that?
Program displays:
You typed "How about that?"
which is: 15 characters long.

The first letter is 'H'

The last letter is '?'

------ Two Random letters ------

The letter at position 1 is 'o'

The letter at position 9 is ' '