Question: a Java or C++ program that will perform the following sequence of operations: 1. Ask the user to input a string. 2. Reverse the first

a Java or C++ program that will perform the following sequence of operations:

1. Ask the user to input a string.

2. Reverse the first word and the last word using a stack/s.

3. Swap the positions of the reversed words.

4. Display the new string.

Sample output:

Input a string :

This is the new normal.

Output : lamron is the new sihT.

If you are going to use the Stack Class, only the following methods are allowed:

empty(), peek(), pop(), and push().

The new string must be stored in another variable.

If the string contains only one word, reverse the word.

If there is a period at the end, do not process it. It must stay in its position.

For sample runs, use the following inputs :

1.) string : This is the new normal.

2.) string : position.

3.) string : the quick brown fox

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 Programming Questions!