Write two `nextInt` statements to get input for `birthMonth` and `birthYear`. Then write a statement to output the month followed by a slash and the year, ending with a newline.

Answered on

Here's how you can write the two `nextInt` statements in Java to get input for `birthMonth` and `birthYear`, followed by a statement to output the formatted date:

```java import java.util.Scanner; // Import the Scanner class

public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Create a Scanner object

System.out.println("Enter your birth month (1-12):"); int birthMonth = scanner.nextInt(); // Read user input for birth month

System.out.println("Enter your birth year (e.g., 1990):"); int birthYear = scanner.nextInt(); // Read user input for birth year

System.out.println("You were born in: " + birthMonth + "/" + birthYear + "\n"); // Output the month and year with a slash in between, ending with a newline } } ```

Note : `import java.util.Scanner;` at the top of your code to import the Scanner class, which allows you to read the user inputs.

Related Questions