Question: Create a new Java class named: LastWord public class LastWord Write a JAVA application program that will get a line of text from the user,

Create a new Java class named: LastWord

public class LastWord

Write a JAVA application program that will get a line of text from the user, and then display the last word in the line.

The following is an example of what your MIGHT see on the screen when your program runs. The exact output depends on what values that the user types in while the program runs. The user's values are shown below in italics:

Enter a sentence: How now brown cow The last word in your sentence is: cow

Here is another example run of the program:

Enter a sentence: We are all part of a family of programmers The last word in your sentence is: programmers

Hints:

If you look at the sentences above, how do you know where the last word starts? The last word is all of the characters which come after the last _____ in the sentence.

There is a String method that will search through a String to find the last time a given character appears.

Once you know where the last word begins, use a String method to extract the last portion of the inputted String.

Store the extracted part in a new String variable.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!