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
DIA [1.3K]
3 years ago
7

(1) prompt the user for a string that contains two strings separated by a comma. (1 pt) examples of strings that can be accepted

: jill, allen jill , allen jill,allen ex: enter input string: jill, allen
Computers and Technology
1 answer:
GalinKa [24]3 years ago
5 0

package parsestrings;

import java.util.Scanner;

public class ParseStrings {

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in); // Input stream for standard input

Scanner inSS = null; // Input string stream

String lineString = ""; // Holds line of text

String firstWord = ""; // First name

String secondWord = ""; // Last name

boolean inputDone = false; // Flag to indicate next iteration

// Prompt user for input

System.out.println("Enter input string: ");

// Grab data as long as "Exit" is not entered

while (!inputDone) {

// Entire line into lineString

lineString = scnr.nextLine()

// Create new input string stream

inSS = new Scanner(lineString);

// Now process the line

firstWord = inSS.next();

// Output parsed values

if (firstWord.equals("q")) {

System.out.println("Exiting.");

inputDone = true;

if (firstWord.matches("[a-zA-Z]+,[a-zA-Z]+")) {

System.out.print("Input not two comma separated words");

}

} else {

secondWord = inSS.next();

System.out.println("First word: " + firstWord);

System.out.println("Second word: " + secondWord);

System.out.println();

}

}

return;

}

}

You might be interested in
Write the definition of the function inputArray that prompts the user to input 20 numbers and stores the numbers into alpha. Wri
Alina [70]

Answer:

In Java:

public static  int[] inputArray(){

   Scanner input = new Scanner(System.in);

   int[] alpha = new int[20];

   for(int i = 0;i<20;i++){

       alpha[i] = input.nextInt();

   }

   return alpha;}

public static  int[] doubleArray(int [] alpha){

   int[] beta = new int[20];

   for(int i = 0;i<20;i++){

       beta[i] = 2 * alpha[i];

   }

   return beta;

}

public static int[] copyAlphaBeta(int [] alpha, int [] beta){

   int [] AlphaBeta = new  int[10];

   for(int i = 0;i<5;i++){

       AlphaBeta[i] = alpha[i];

   }

   int count = 5;

   for(int i = 15;i<20;i++){

       AlphaBeta[count] = beta[i];

       count++;

   }

   return AlphaBeta;

}

public static void printArray(int [] alpha){

   for(int i = 0;i<20;i++){

       System.out.print(alpha[i]+" ");

       if((i+1)%15 == 0){

           System.out.println(" ");

       }

   }

}

Explanation:

The inputArray is defined here

public static  int[] inputArray(){

   Scanner input = new Scanner(System.in);

This declares alpha array of 20 elements

   int[] alpha = new int[20];

The following iteration gets input from the user into the array

<em>    for(int i = 0;i<20;i++){</em>

<em>        alpha[i] = input.nextInt();</em>

<em>    }</em>

This returns the alpha array

   return alpha;}

The doubleArray is defined here. It takes the alpha array as its input parameter

public static  int[] doubleArray(int [] alpha){

This declares beta of 20 integers

   int[] beta = new int[20];

This populates beta by 2 * alpha[i]

<em>    for(int i = 0;i<20;i++){</em>

<em>        beta[i] = 2 * alpha[i];</em>

<em>    }</em>

This returns the alpha array

   return beta;}

The copyAlphaBeta array is defines here

public static int[] copyAlphaBeta(int [] alpha, int [] beta){

This declares AlphaBeta as 10 elements

   int [] AlphaBeta = new  int[10];

This populates the first 5 elements of AlphaBeta with the first 5 of alpha

<em>    for(int i = 0;i<5;i++){</em>

<em>        AlphaBeta[i] = alpha[i];</em>

<em>    }</em>

   int count = 5;

This populates the last 5 elements of AlphaBeta with the last 5 of beta

<em>    for(int i = 15;i<20;i++){</em>

<em>        AlphaBeta[count] = beta[i];</em>

<em>        count++;</em>

<em>    }</em>

This returns the AlphaBeta array

   return AlphaBeta;

}

The printArray is defined here. It takes the alpha array as its input parameter

public static void printArray(int [] alpha){

This iterates through alpha array

   for(int i = 0;i<20;i++){

This prints each element of the array

       System.out.print(alpha[i]+" ");

A new line is started after the 15th element

<em>        if((i+1)%15 == 0){</em>

<em>            System.out.println(" ");</em>

<em>        }</em>

   }

}

See attachment for complete program which includes the main

Download txt
4 0
2 years ago
Company that offers Internet access to individuals and businesses. This device connects two or more networks and directs the flo
Ganezh [65]

Answer:

ISP is the correct answer to the following question.

Explanation:

ISP(Internet Service Provider) is the company or an organization which provides the internet connection or access to any persons, individuals or any company. It is the device that connects networks and direct flow of the data or information through the network. If you want to connect through ISP then, you have to connect this device to the computer system.

5 0
3 years ago
Horizontal and vertical flips are often used to create ___.
mixer [17]

Answer:

Rotation of an image

Explanation:

The correct answer is -  Rotation of an image

Reason -

When you rotate an object, it moves left or right around an axis and keeps the same face toward you.

When you flip an object, the object turns over, either vertically or horizontally, so that the object is now a mirror image.

5 0
2 years ago
Biometric devices are often associated with computer and data security. True False
Leya [2.2K]

Answer:

True

Explanation:

5 0
3 years ago
Which of the following BEST represent the Scrum approach to planning?
evablogger [386]

Answer:

this is the answer I think

7 0
2 years ago
Other questions:
  • The tone a writer takes is referred to as the writing _____.
    7·2 answers
  • I'm 11, except my profile says I'm 15.
    15·1 answer
  • Florida Highway Safety and Motor Vehicles reported blank of traffic fatalities were alcohol-related in Florida in 2009.​
    8·1 answer
  • A ___ is an organized collection of data in digital format that helps users to keep
    5·1 answer
  • Please tell me what is basic HTML tags and its function please ​
    8·1 answer
  • When USB flash drives started becoming popular, customers stopped purchasing CDs. As a result, USB flash drives almost completel
    5·1 answer
  • Which can be used to create a poll on a web page? <br>CSS<br>HTML <br>JavaScript <br>Text editor​
    12·1 answer
  • Which of these is not an example of a transition
    6·1 answer
  • A good machine should have the mechanical advantage of......?​
    7·1 answer
  • How was data put into the Tabulating Machine?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!