85.6k views
1 vote
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 Note: The input values come from user input, so be sure to use scnr.nextInt statements, as in birthMonth

1 Answer

2 votes

Final answer:

To get input values into birthMonth and birthYear, use scnr.nextInt() twice and then output the values separated by a slash followed by a newline using System.out.println.

Step-by-step explanation:

To read input values into birthMonth and birthYear using scnr.nextInt(), you need to call this method twice, once for each variable. After obtaining these values from the user, you can then print them out in the specified format with a slash in between followed by a newline character.

Here's what the code in Java might look like:

int birthMonth = scnr.nextInt(); // Reads the first input for the month
int birthYear = scnr.nextInt(); // Reads the second input for the year
System.out.println(birthMonth + "/" + birthYear); // Outputs the month/year in the specified format

Make sure to use the nextInt() method for both birthMonth and birthYear, and use println to ensure that the output ends with a newline.

User Bansi
by
7.1k points