131k views
5 votes
Write two Get statements to get input values into first Month and first Year. Then write three Put statements to output the month, a slash, and the year. Ex: If the input is 1 2000, the output is:

1 Answer

4 votes

Answer:

// Scanner class is imported

import java.util.Scanner;

// InputExample class to hold the program

public class InputExample {

// main method to begin program execution

public static void main(String args[]) {

// Scanner object scnr is created

Scanner scnr = new Scanner(System.in);

// variable birthMonth is declared

int birthMonth;

// variable birthYear is declared

int birthYear;

// birthMonth is initialized to 1

birthMonth = 1;

// birthYear is initialized to 2000

birthYear = 2000;

// birthday is displayed

System.out.println("1/2000");

// prompt is displayed asking user to enter birthMonth

System.out.println("Enter birthMonth:");

// birthMonth is received using Scanner object

birthMonth = scnr.nextInt();

// prompt is displayed asking user to enter birthYear

System.out.println("Enter birthYear:");

// birthYear is received using Scanner object

birthYear = scnr.nextInt();

// the birthday format is displayed

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

}

}

Step-by-step explanation:

The program is written in Java as required and it is well commented.

An image depicting the full question is attached.

Write two Get statements to get input values into first Month and first Year. Then-example-1
User Dhia Shalabi
by
5.3k points