subject

Parsing strings (Java) (1) Prompt the user for a string that contains two strings separated by a comma. (1 pt)
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
must use this as part of the solution:
import java. util. Scanner;
public class ParseStrings {
public static void main(String[] args) {
/* Type your code here. */
Scanner scnr = new Scanner(System. in);
String lineString = "";
String firstName;
String lastName;
boolean inputDone;
System. out. println("Enter input string: ");
lineString = scnr. nextLine();
while (lineString. indexOf(',') == -1){
System. out. println("Error: No comma in string");
System. out. println("Enter input string: ");
lineString = scnr. nextLine();
inSS = new Scanner(userInfo);
// Parse name and age values from string
firstName = inSS. next();
lastName = inSS. next();
}
return;
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 02:00
Which of the following is not a source of sustainable raw materials? a) coal mine b) flick of sheep c) cotton plantation d) line forest.
Answers: 2
question
Computers and Technology, 23.06.2019 11:20
Http is the protocol that governs communications between web servers and web clients (i.e. browsers). part of the protocol includes a status code returned by the server to tell the browser the status of its most recent page request. some of the codes and their meanings are listed below: 200, ok (fulfilled)403, forbidden404, not found500, server errorgiven an int variable status, write a switch statement that prints out the appropriate label from the above list based on status.
Answers: 2
question
Computers and Technology, 23.06.2019 12:00
3. when you right-click a linked spreadsheet object, what commands do you choose to activate the excel features? a. linked worksheet object > edit b. edit data > edit data c. linked spreadsheet > edit d. object > edit data
Answers: 2
question
Computers and Technology, 23.06.2019 15:00
Based on the current economic situation do you expect the employment demand for graduating engineers to increase or decrease? explain the basis for your answer. with a significant economic recovery, what do you think will happen to future enrollments in graduating engineering programs?
Answers: 1
You know the right answer?
Parsing strings (Java) (1) Prompt the user for a string that contains two strings separated by a co...
Questions
question
Mathematics, 10.04.2020 19:03
question
Biology, 10.04.2020 19:03
question
Mathematics, 10.04.2020 19:03
question
Mathematics, 10.04.2020 19:03
Questions on the website: 13722360