[Question & Answer] 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 or pressed for time? – Don’t worry, we have a team of professionals to help you on
[Question & Answer] 5.6 Warm up: Parsing strings (Java)…..
Get a 15% Discount on this Paper
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

6.6.1: warm up: parsing strings (python 3)

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

6.6.1: warm up: parsing strings (python 3)

 

 

 

So much stress and so little time? We’ve got you covered. Get your paper proofread, edited or written from scratch within the tight deadline.

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.
Sign up, place your order, and leave the rest to our professional paper writers in less than 2 minutes.
step 1
Upload assignment 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.
s
Get personalized services with MyCoursebay
One writer for all your papers
You can select one writer for all your papers. This option enhances the consistency in the quality of your assignments. Select your preferred writer from the list of writers who have handledf your previous assignments
Same paper from different writers
Are you ordering the same assignment for a friend? You can get the same paper from different writers. The goal is to produce 100% unique and original papers
Copy of sources used
Our homework writers will provide you with copies of sources used on your request. Just add the option when plaing your order
What our partners say about us
We appreciate every review and are always looking for ways to grow. See what other students think about our do my paper service.
Nursing
Great work! I can tell they put great effort in completing this assignment. Thank you.
Customer 452707, October 14th, 2022
Marketing
Thank you great job
Customer 452813, July 10th, 2022
Human Resources Management (HRM)
You are greatly appreciated.
Customer 452701, October 17th, 2023
Social Work and Human Services
Excellent Work
Customer 452587, November 22nd, 2021
Nursing
Another great paper! Thank you!
Customer 452707, June 16th, 2022
Criminal Justice
Impressive! Will be using the service again.
Customer 452485, December 5th, 2021
Other
AWESOME
Customer 452813, July 5th, 2022
Nurse
Great work! Thank you for the quality you put in each assignment.
Customer 452707, February 4th, 2022
Social Work and Human Services
Thank you
Customer 452559, July 2nd, 2021
Business and administrative studies
Thank you very much for your help.
Customer 452861, September 16th, 2022
Nursing
Great paper!
Customer 452707, June 29th, 2023
Other
Great Work!
Customer 452587, March 10th, 2022
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

Good News ! We now help with PROCTORED EXAM. Chat with a support agent for more information

NEW

Thank you for choosing MyCoursebay. Your presence is a motivation to us. All papers are written from scratch. Plagiarism is not tolerated. Order now for a 15% discount

Order Now