Write code that uses the input string stream inSS to read input data from string userInput, and updates variables userMonth, userDate, and userYear. Sample output if the input is "Jan 12 1992": Month: Jan Date: 12 Year: 1992

Respuesta :


The Code Looks Like this :

import java.util.Scanner;
public class StringInputStream {
public static void main (String [] args) {
Scanner inSS = null;
String userInput = "Jan 12 1992";
inSS = new Scanner(userInput);
String userMonth = "";
int userDate = 0;
int userYear = 0;
/* Your solution goes here */
inSS.useDelimiter(" ");
userMonth=inSS.next();
userDate=inSS.nextInt();
userYear=inSS.nextInt();
System.out.println("Month: " + userMonth);
System.out.println("Date: " + userDate);
System.out.println("Year: " + userYear);
return;
}
}

Out Put:

Month: Jan

Date: 12

Year: 1992

Following are the java program to separing the string value:

Program Explanation:

  • Import package.
  • Defining a class Main.
  • Defining the main method.
  • Inside the method, a Scanner class type variable "inSS" is define that reads "userInput" a string variable value.
  • In the next step, one string and two integer variable "userMonth, userDate, and userYear" is defined that separe its value by using "useDelimiter" method, and print its value with the message.

Program:

import java.util.*;//import package

public class Main //defining a class main

{

public static void main (String [] ars) //main method

{

Scanner inSS = null;//using Scanner  

String userInput="Jan 12 1992";//defining a String variable userInput that holds a string value

inSS = new Scanner(userInput);//passing userInput value into Scanner class

String userMonth = "";//defining a String variable

int userDate = 0,userYear = 0;//defining an integer variable

inSS.useDelimiter(" ");//calling method useDelimiter

userMonth=inSS.next();//holding value in to the variable

userDate=inSS.nextInt();//holding value in to the variable

userYear=inSS.nextInt();//holding value in to the variable

System.out.println("Month: " + userMonth);//print value with message

System.out.println("Date: " + userDate);//print value with message

System.out.println("Year: " + userYear);//print value with message

return;

}

}

Output:

Please find the attachment file.

Learn more:

brainly.com/question/14063644

Ver imagen codiepienagoya