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
Most portable devices, and some computer monitors have a special steel bracket security slot built into the case, which can be u
Artemon [7]

Answer:

Instead of using a key or entering a code to open a door, a user can use an object, such as an ID badge, to identify themselves in order to gain access to a secure area. What term describes this type of object?

Explanation:

6 0
2 years ago
Exchanging which type of data uses the least bandwidth?
Over [174]
Voice. voice uses the least bandwidth
5 0
3 years ago
Read 2 more answers
The amount of data that can be stored on a disk depends in part on_____.
MariettaO [177]
To what it seems like, it’s d
8 0
3 years ago
Assume you have a button control named btndisplaylist. Which is the default name for an event procedure that will be executed wh
dybincka [34]

The default name for an event procedure that will be executed when the user clicks on the control will be btnDisplayListclick.

<h3>What is a default name?</h3>

It should be noted that a default name means a name that's assigned to a folder that's created in a computer.

In this case, the default name for an event procedure that will be executed when the user clicks on the control will be btnDisplayListclick.

Learn more about default on:

brainly.com/question/23976472

#SPJ12

8 0
2 years ago
Which best explains a password attached to a document?
Otrada [13]
That is encryption. Encrypted files usually have a password assigned. In order to decrypt the file, you need to have the password.
3 0
3 years ago
Other questions:
  • Anderson uses his computer and internet link to chart the movement of his favorite 46 stocks. He buys and sells according to the
    15·1 answer
  • A label is any word that appears in a cell of a spreadsheet.<br> True<br> False
    5·2 answers
  • In which of the following scenarios would you use the Redo function?
    12·1 answer
  • A function ________ contains the statements that make up the function.
    5·1 answer
  • What is a boolean in Java
    5·1 answer
  • !WILL MARK BRAINLIEST!
    8·1 answer
  • Your organization uses a type of cryptography that provides good security but uses smaller key sizes and utilizes logarithms tha
    9·1 answer
  • In cell n2, enter a formula using the if function and a structured reference to determine if allison simoneau is eligible for tu
    11·1 answer
  • Which of the following is NOT an example of soft skill?
    8·1 answer
  • Complete each sentence
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!