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 a switch statement, if a break statement is missing, _______________. Select one: a. the default case is automatically execut
Aleks [24]

Answer:

c. execution falls through the next branch until a break statement is reached

Explanation:

In a switch statement, if break is missing, then program continues to the next cases until it finds a break statement.

Consider the following example!

Example:

#include <iostream>

using namespace std;

int main()

{

  int choice = 1;

  switch (choice)

  {

      case 1:

      printf("This is case 1, No break\n");

      case 2:

      printf("This is case 2, No break\n");

      case 3:

      printf("This is case 3, with break\n");

      break;

      default: printf("Error! wrong choice\n");

  }

  return 0;

}

Output:

This is case 1, No break

This is case 2, No break

This is case 3, with break

We have 3 cases here and case 1 and 2 don't have break statements, only case 3 has a break statement.

We called the case 1, then program continued to case 2,  and finally to case 3 where it finds the break statement and terminates.

Therefore, we conclude that in a switch statement, if a break statement is missing, then execution falls through the next branch until a break statement is found.

8 0
3 years ago
A keyboard shortcut is a key or combination of keys that you press to access a feature or perform a command. ___________________
andrey2020 [161]
I believe that this is true.
Ctrl+F
Ctrl+C
Ctrl+V
These are all keyboard shortcuts.

8 0
3 years ago
1.5 question 3 on edhesieve
morpeh [17]

Answer:

ppl

Explanation:

asfafgdffsghsdfghdgsghdfghtrbd54445 ddfgg

7 0
3 years ago
Which option allows to change date and time​
tester [92]
The Windows key has the Windows logo on it. Right-click the Date/Time display on the taskbar and then choose Adjust Date/Time from the shortcut menu. The Date and Time dialog box appears. Click the Change Date and Time button.
4 0
3 years ago
Read 2 more answers
Software that manages the resources of the computer is called:
AleksAgata [21]
A. Data management software.
6 0
2 years ago
Other questions:
  • Tower defense is included under which genre of game
    15·2 answers
  • What privacy issues have arisen with webcams in mobile devices?
    8·1 answer
  • Bitnet, one of the predecessors of the internet was launched in 1981. what does bitnet stand for?
    12·1 answer
  • Which of the following statements about Linux is not​ true? A. Linux works on all the major hardware platforms. B. It plays a ma
    5·1 answer
  • Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow each number by a space.
    7·1 answer
  • Which method do software testers use to isolate new code from the rest of the network during the test stage of the software deve
    15·1 answer
  • Create a class named Console, and move all the methods that retrieve and validate user input to that class. These methods can re
    7·1 answer
  • D. DROP
    6·1 answer
  • Whats yall favv scary movie
    11·1 answer
  • How has the internet improved business communication worldwide
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!