Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 8.2: String Manipulation (10 pts) Complete each of the following String manipulation problems in a file called Manip.java. Your program should read in two

Assignment 8.2: String Manipulation (10 pts)

Complete each of the following String manipulation problems in a file called Manip.java. Your program should read in two Strings from the keyboard as shown below. It should then do the following:

Measure the length of both words entered by the user and save the length in the related variable. Then use an if-statement to compare the two word lengths and print the word that is longer.

Determine whether the two words are the same (Hint: remember the equals method?)

Concatenate the first 2 letters of the variable first and the last 3 letters of variable second. Assign the result of the concatenation operations to variable extract. Hint: Use charAt()

Note that you may assume the user enters words of sufficient length to complete this step

Compare the two words using compareTo to determine which one comes first alphabetically.

Sample Output: The input prompts and outputs of the program must look like the following for full credit, including the same order of input and exact wording of the output. For the input shown you must get the same output. However, the output must change properly if the inputs are different.

*** String Manipulation ***

Enter two words separated by a space, and press the Enter key

Enter your input: Hello World!

You entered: first = "Hello" and second = "World!"

First word length: 5

Second word length: 6

Longer word: World!

Words are the same: false

Merged words: Held!

Word order: Hello comes before World!

In the sample output, the user entered the words shown in italics (for emphasis) to produce the output. Your program does NOT print the characters in italics, nor does the user input appear in italics.

*** String Manipulation ***

Enter two words separated by a space, and press the Enter key

Enter your input: Bye Bye

You entered: first = "Bye" and second = "Bye"

First word length: 3

Second word length: 3

Longer word: Bye

Words are the same: true

Merged words: ByBye

Word order: Bye comes before Bye

After displaying the output, exit the program. Submit your file to Canvas once it is complete.

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

Intelligent Information And Database Systems 6th Asian Conference Aciids 2014 Bangkok Thailand April 7 9 2014 Proceedings Part I 9 2014 Proceedings Part 1 Lnai 8397

Authors: Ngoc-Thanh Nguyen ,Boonwat Attachoo ,Bogdan Trawinski ,Kulwadee Somboonviwat

2014th Edition

3319054759, 978-3319054759

More Books

Students also viewed these Databases questions