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
Word offers a multitude of picture formatting options that allow you to flip, rotate, and make many other adjustments to inserte
SIZIF [17.4K]

Answer:

True

Explanation:

In Microsoft Word, there are several formatting options available to format the inserted picture. Whenever we insert a picture, the picture formatting options will appear at the top of the program. One of the option, Rotate, enable user to rotate the picture 90 degree to the left or right and flip it vertically or horizontally. Besides, Word formatting options also include Crop feature, Color Corrections, Transparency Adjustment etc.

8 0
4 years ago
Where are Micro USB connectors used the most?
jeka94

Answer:

desktops............

3 0
3 years ago
Read 2 more answers
Write any two rules for writing algorithm​
inessss [21]

Answer:

1) = input and output should be defines precisely

2) = it shouldn't include computer code

5 0
3 years ago
3
sergiy2304 [10]

Answer: I believe this would be A.) choosing an alternative

Explanation:

6 0
3 years ago
Read 2 more answers
Where can the Ease of Access and Speech Recognition centers be found?
Bess [88]

Answer:

bottom right

Explanation:

at least on windows it's bottom right

3 0
4 years ago
Read 2 more answers
Other questions:
  • Question 1 (1 point)
    10·2 answers
  • Which actions should be taken so that transitions proceed automatically? Check all that apply.
    12·2 answers
  • An example of a current disruptive technology is a?
    8·2 answers
  • Using symbols (%, $, #, etc.) can make it easier to take notes.
    8·2 answers
  • Caleb is a big fan of science fiction, so he loves picturing the ________ gland as the captain of his personal starship, pulling
    9·1 answer
  • _____ describes the layout of the screen. Block-based, Interface, Editor, Player
    11·2 answers
  • For all programs, you should write a small amount of code and _______
    6·1 answer
  • 3.5 code practice question 1
    5·2 answers
  • Explain any two types of board band connection​
    11·1 answer
  • Explain how to add cell A1 and cell B3 in excel
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!