[SOLVED] 5.6 Warm up: Parsing strings (Java)

5.6 Warm up: Parsing strings (Java)

(1) Prompt the user for a string that contains two strings separated by a comma. (1 pt)

Struggling to find relevant content? Order a custom essay on
[SOLVED] 5.6 Warm up: Parsing strings (Java)
Let our experts save you the hassle
Order Now

Examples of strings that can be accepted:

Jill, Allen

Jill , Allen

Jill,Allen

Ex:

Enter input string: Jill, Allen

(2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. (2 pts)

Ex:

Enter input string: Jill Allen
Error: No comma in string
Enter input string: Jill, Allen

(3) Extract the two words from the input string and remove any spaces. Store the strings in two separate variables and output the strings. (2 pts)

Ex:

Enter input string: Jill, Allen
First word: Jill
Second word: Allen

(4) Using a loop, extend the program to handle multiple lines of input. Continue until the user enters q to quit. (2 pts)

Ex:

Enter input string: Jill, Allen
First word: Jill
Second word: Allen
Enter input string: Golden , Monkey
First word: Golden
Second word: Monkey
Enter input string: Washington,DC
First word: Washington
Second word: DC

Enter input string: q

Expert Answer

Tested on Eclipse with Java-8

package stringclass;

import java.util.Scanner;

// TODO: Auto-generated Javadoc

/**

* The Class ParsingString.

* @author Lalchand Mali.

*/

public class ParsingString {

/**

* The main method.

*

* @param args the arguments

*/

public static void main(String[] args) {

String userInput;

Scanner input = new Scanner(System.in);

/**

* Taking input from user

*/

System.out.print(“Enter input string: “);

userInput = input.nextLine();

/**

* Loop continue until userInput not equal to q

*/

while(!userInput.equals(“q”)) {

/**

* If input contain comm then split it

* otherwise print error with message

* and continue for user input

*/

if(userInput.contains(“,”)){

String[] arr = userInput.split(“,”);

System.out.println(“First Word:” + arr[0].trim());

System.out.println(“Second Word:” + arr[1].trim());

} else{

System.out.println(“Error: No comma in string”);

}

System.out.print(“Enter input string: “);

userInput = input.nextLine();

}

/**

* closing Scanner stream.

*/

if(input!=null){

input.close();

}

}

}

/**************************Output***************************/

Enter input string: Jill Allen
Error: No comma in string
Enter input string: Jill, Allen
First Word:Jill
Second Word:Allen
Enter input string: Golden , Monkey
First Word:Golden
Second Word:Monkey
Enter input string: Washington,DC
First Word:Washington
Second Word:DC
Enter input string: q

Related: Sample Projects in C#: Consecutive Numbers in Gray Code Sequence

Don’t worry, however, if you still have no idea how to do this task – you have a team of professionals to help you. All you need to do is fill in the order form in the upper right corner and upload the files that are crucial for your assignment. Also, don’t forget to specify whether your assignment has to be based upon a specific research, theory or method. After that, you will be asked to choose an expert you liked the most from those who have placed their bids under your order. You can always chat with your expert and ask any questions you have during the working process, and you will be asked to pay only after you receive a maximum subarray problem solved the way you needed it to be solved.
Tags: 5.6 warm up: parsing strings (java)

Calculate the price
Make an order in advance and get the best price
Pages (550 words)
$0.00
*Price with a welcome 15% discount applied.
Pro tip: If you want to save more money and pay the lowest price, you need to set a more extended deadline.
We know how difficult it is to be a student these days. That's why our prices are one of the most affordable on the market, and there are no hidden fees.

Instead, we offer bonuses, discounts, and free services to make your experience outstanding.
How it works
Receive a 100% original paper that will pass Turnitin from a top essay writing service
step 1
Upload your instructions
Fill out the order form and provide paper details. You can even attach screenshots or add additional instructions later. If something is not clear or missing, the writer will contact you for clarification.
Pro service tips
How to get the most out of your experience with GPA Fix
One writer throughout the entire course
If you like the writer, you can hire them again. Just copy & paste their ID on the order form ("Preferred Writer's ID" field). This way, your vocabulary will be uniform, and the writer will be aware of your needs.
The same paper from different writers
You can order essay or any other work from two different writers to choose the best one or give another version to a friend. This can be done through the add-on "Same paper from another writer."
Copy of sources used by the writer
Our college essay writers work with ScienceDirect and other databases. They can send you articles or materials used in PDF or through screenshots. Just tick the "Copy of sources" field on the order form.
Testimonials
See why 20k+ students have chosen us as their sole writing assistance provider
Check out the latest reviews and opinions submitted by real customers worldwide and make an informed decision.
Eng 099
I recveived a B on this paper but I'm not sure why.
Customer 452775, June 18th, 2022
Nursing
Thank you!!!
Customer 452557, June 26th, 2021
Ethics
thank you
Customer 452493, March 15th, 2021
Other
GOOD
Customer 452813, July 10th, 2022
Business and administrative studies
GREAT
Customer 452813, June 30th, 2022
Other
great
Customer 452813, June 25th, 2022
Other
GOOD
Customer 452813, July 5th, 2022
Other
Great Work!
Customer 452587, March 10th, 2022
Nursing
Fantastic work on this project as usual.
Customer 452707, July 5th, 2022
Other
GREAT JOB THANK YOU.
Customer 452813, July 18th, 2022
Other
great
Customer 452813, June 30th, 2022
Education
Thank you so much for your help so I do not go insane from trying to do this. I have 2 more courses to do. Probably will be using you again.
Customer 452675, November 28th, 2021
11,595
Customer reviews in total
96%
Current satisfaction rate
3 pages
Average paper length
37%
Customers referred by a friend
OUR GIFT TO YOU
15% OFF your first order
Use a coupon FIRST15 and enjoy expert help with any task at the most affordable price.
Claim my 15% OFF Order in Chat