Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions