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, 22.06.2019 15:00
Atool that matches persoal skills qualities interests and talets to a career is called a
Answers: 1
question
Computers and Technology, 23.06.2019 18:00
Apunishment or the threat of punishment used to enforce conformity. select the best answer from the choices provided t f
Answers: 1
question
Computers and Technology, 23.06.2019 20:00
How much current flows through the alternator brushes? a. 2–5 a b. 25–35 a, depending on the vehicle c. 5–10 a d. 10–15 a
Answers: 2
question
Computers and Technology, 24.06.2019 10:50
In 2009 to 2010, how many social network users were reported as being victims of online abuse? a. 1 in 10 b. 100% c.1 in 100 d. 50%
Answers: 2
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, 27.05.2021 02:40
question
Mathematics, 27.05.2021 02:40
question
Mathematics, 27.05.2021 02:40
question
Mathematics, 27.05.2021 02:40
Questions on the website: 13722363