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
Hello everyone! can anybody help me? i need help with computing.
timurjin [86]

Answer:

a pseu code is a is an artificial and informal language that helps programmers develop algorithms.

Explanation:

7 0
3 years ago
A class is a _____, which encapsulates _____ and _____. (Points : 2) programming language construct; attributes; behavior
dimaraw [331]

Answer:

A class is a programming language template, which encapsulates methodes and behavior.

Explanation:

In OOP (object-oriented programming), a class is programming language template to create objects (instance of a class),  which encapsulates methodes and implementations of behavior (action which an object is able to perform)

8 0
3 years ago
Launched in 1995, ________ has become the most popular web browser.
kicyunya [14]
It’s Internet explorer
6 0
3 years ago
What is a symptom of a failing power supply? The display has only a blinking cursor. The computer displays a POST error code. Th
Mariulka [41]

Answer:

A sympton of a failing power supply is The computer sometimes does not turn on.

Explanation:

All right, the power supply is the terminal that receives electric current to process it and distribute it to the different parts of the hardware that compose the computer. When it fails, the current is not distributed and doesn't reach the different pieces of hardware. Therefore, option D) is the correct one. Another error that could be related is the malfunction of fans but it could be related to wires more than the power itself.

7 0
3 years ago
Convert one billion byte into one storage unit​
notka56 [123]

Answer:

Explanation:

To convert larger units to smaller units (i.e. take a number of gigabytes and convert it down in to megabytes, kilobytes, or bytes) you simply multiply the original number by 1,024 for each unit size along the way to the final desired unit

7 0
3 years ago
Other questions:
  • Differentiate between third and fourth generation of computer​
    6·1 answer
  • What are the disadvantages of using pointers?
    6·1 answer
  • What is the default font style of “Title” box in MS PowerPoint 2013?
    8·1 answer
  • Calculate the total and average number from 1 to 100<br>​
    12·1 answer
  • Guys, please help me asap (Photo Attached) !!!!!!! HELP 25pts!!!!
    14·2 answers
  • How can a classroom be more effective by the use of multimedia? ​
    12·1 answer
  • Who designed the apple i computer in 1976?
    13·1 answer
  • How are the waterfall and agile methods of software development similar?
    13·1 answer
  • ________ helps in determining the cause of a security threat in an incident response plan. Question 7 options: A) Restricting sy
    5·1 answer
  • Which website offers guidance on putting together a checklist to provide guidance on configuring and hardening operating systems
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!