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
A pair of single quotes ' will prevent the shell from interpreting any special character. True or False
Stells [14]

Answer:

The answer is "True".

Explanation:

A single quote is a punching mark also known as an apostrophe located on the US Standard keyboard near the Enter button.

  • It's also known as a direct quote, such markings are also used in a news article for marking a statement. If a paragraph is a capital letter within the next quote, it is a function of a single quote. It refers to verbal marks.
  • A couple of quotes will avoid a unique character becoming interpreted by only the shell, that's why the given statement is true.
3 0
3 years ago
In ip address 202.54.15.178, 15.178 is ______ address.
Tpy6a [65]

Answer:

Network address--An IP address with a host portion that is all zeros. Octet--An 8-bit number, 4 of which comprise a 32-bit IP address. They have a range of 00000000-11111111 that correspond to the decimal values 0-255. Packet--A unit of data passed over a TCP/IP network or wide area network.

7 0
2 years ago
Discuss why diffrent user interface require the use of diffrent type of input device<br>​
Bas_tet [7]

Discuss why different user interfaces require the use of different types of input device. Page 15. What is Secondary Storage? List 3 Storage Mediums: What is ...

mark me brain list

7 0
2 years ago
Social media applications' main purpose is to allow users to watch movies and TV shows, listen to music, and read books online.
Novosadov [1.4K]

Answer: I dont really know but im guessing it depends on the type of assignment you have. im thinking True.

Explanation:

4 0
3 years ago
Beside homework, what products can you use for personal use? Identify three uses and briefly describe.
Dominik [7]
<span>Beside homework, what products can you use for personal use? Identify three uses and briefly describe.

</span>
3 0
3 years ago
Read 2 more answers
Other questions:
  • A publisher has a text-only leader board on top of a page, and a text-only small square ad slot within the content of that page.
    7·1 answer
  • Linguist study
    9·1 answer
  • Cliff just started working with a client who has a very disorganized AdWords account. What’s an effective way for him to begin r
    15·1 answer
  • What is the name of the amount of space between the content of a document and the edge of the page
    13·1 answer
  • An ironworker standing 30 feet in the air is safe wearing a full body harness that is not tied off
    15·2 answers
  • Excerpt from "How Prepared Are Students for College Level Reading? Applying a Lexile-Based Approach."
    6·1 answer
  • Please answer me fast ​
    6·2 answers
  • Laptops are used for accessing the internet. Name two advantages and two disadvantages for using a laptop rather than a smartpho
    5·2 answers
  • Write a function called changeCharacter that takes three parameters – a character array, its size, and the replacement character
    15·1 answer
  • This is an image of the ...........................Topology.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!