82.7k views
0 votes
Write two scnr.nextInt statements to get input values into birthMonth and birthYear. Then write a statement to output the month, a slash, and the year. End with newline. The program will be tested with inputs 1 2000, and then with inputs 5 1950. Ex: If the input is 1 2000, the output is: 1/2000

User Shammara
by
5.3k points

1 Answer

2 votes

Answer:

Here is code in Java.

// import package

import java.util.*;

class Main

{ // main method of class

public static void main (String[] args) throws java.lang.Exception

{

try{

// variables to store the input

int birthMonth,birthYear;

// Scanner class object to read the input

Scanner scnr=new Scanner(System.in);

System.out.print("Please enter the birth month:");

// read the birth month

birthMonth=scnr.nextInt();

System.out.print("Please enter the birth year:");

// read the birth year

birthYear=scnr.nextInt();

// print the output

System.out.println(birthMonth+"/"+birthYear+"\\");

}catch(Exception ex){

return;}

}

}

Step-by-step explanation:

Create two variables "birthMonth" & "birthYear" to store the birth month and birth year.Read the values of both from user. Print the birth month and birth year separated by a slash("/").

Output:

Please enter the birth month:1

Please enter the birth year:2000

1/2000

Please enter the birth month:5

Please enter the birth year:1950

5/1950

User Lucas Moeskops
by
4.8k points