1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
bazaltina [42]
3 years ago
5

Prompt the user for a string that contains two strings separated by a comma. (1 pt)Examples of strings that can be accepted:Jill

, AllenJill , AllenJill,AllenEx: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 AllenError: No comma in string.Enter input string: Jill, Allen(3) Using string splitting, extract the two words from the input string and then remove any spaces. Output the two words. (2 pts)Ex:Enter input string:Jill, AllenFirst word: JillSecond 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, AllenFirst word: JillSecond word: AllenEnter input string:Golden , MonkeyFirst word: GoldenSecond word: MonkeyEnter input string:Washington,DCFirst word: WashingtonSecond word: DCEnter input string:
Computers and Technology
1 answer:
Veronika [31]3 years ago
7 0

Answer:

import java.util.Scanner;

public class ParseStrings {

public static void main(String[] args) {

/* Type your code here. */

Scanner sc= new Scanner(System.in);//to read inout from user

String sentence;//to hold user input

System.out.println("Enter input string");//asking user to input string reading into sentence

sentence=sc.nextLine();

while(!sentence.equals("q"))//continues untill user enters q

{

while(!sentence.contains(","))//loop ti eport error and continue till user enters valid string

{

System.out.println("No comma in string");

System.out.println("Enter input string");

sentence=sc.nextLine();

}

//extracting words from senetnece

String word1=sentence.substring(0, sentence.indexOf(',')).trim();

String word2=sentence.substring(sentence.indexOf(',')+1).trim();

System.out.println("First word:"+word1);

System.out.println("Second word:"+word2);

System.out.println("Enter input string");//asking user to input string reading into sentence

sentence=sc.nextLine();

}

 

return;

}

}

Explanation:

You might be interested in
In order for two computers to communicate via the internet, they must first locate one another. How do computers locate one anot
PolarNik [594]

by the IP address of the computer

a computer is located by the IP address

6 0
3 years ago
In a new worksheet, you must start by typing in cell A1.
irinina [24]
The answer issssss.. true
6 0
3 years ago
( Game Design) The companies who get video games out to consumers are called:
Bad White [126]

Answer:

They are called video game publishers

Explanation:

A video game publisher is responsible for financing a video game’s development, marketing, and release of the game to the consumers. Basically, they are the ones who manage the business end of the gaming field. If the video game company is well established, the publishers of that company will be the ones to distribute while some smaller companies will hire distribution companies to distribute the games for them

3 0
3 years ago
what properties are associated with all Microsoft Office files and include author, title, and subject
dolphi86 [110]
<span>The standard properties are associated with all Microsoft Office files and include author, title, and subject.
</span> <span>By default, </span>Microsoft Office<span> documents are associated with a set of these </span>standard properties.<span> They make it easier to organize and identify your documents. </span>
6 0
3 years ago
The part of the poppet valve that contacts the valve seat is called the A. face. B. margin. C. head. D. stem.
Phantasy [73]
It should be A face, I think
6 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following was the first commercial software package to incorporate WYSIWYG as a feature?
    15·1 answer
  • Which of these components is a part of the central processing unit (cpu) of a computer??
    14·1 answer
  • (Display nonduplicate words in ascending order)
    11·1 answer
  • Write a program that prompts a user to enter numeric values. As each value is entered, the program should: - Append the value to
    7·1 answer
  • Today when Dylan turned on his computer, he noticed that the monitor was very dim. He could still see the desktop icon and text.
    15·1 answer
  • Which is a characteristic of multimedia systems?
    7·1 answer
  • viewRatings(string, int) Takes a username and a minimum rating value. It prints all the books that the user has rated with a val
    10·1 answer
  • Assume myString and yourString are variables of type String already declared and initialized. Write ONE line of code that sets y
    15·1 answer
  • List 10 ways how can graphic design help the community
    13·1 answer
  • at the command prompt, type ls -l myscript and press enter. what permissions does the myscript file have? next, type bash myscri
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!