Edit java program user is prompted for new input


Discuss the below:

Q: Edit Java program that user is prompted for new input or exit program by the question "Do you wish to continue (y/n):"

Please provide two files MonthNumber.java and MonthNumberApp.java and comment the code clearly.

import java.util.*; // class Scanner

public class MonthNumber

{
public static void main(String args[])

{
Scanner input = new Scanner(System.in);

while (true) // endless loop

{
System.out.println("Please enter month number to get month name (abort program with x): ");

int month = input.nextInt();

if (month == 1) System.out.println("January");

else if (month == 2) System.out.println("February");

else if (month == 3) System.out.println("March");

else if (month == 4) System.out.println("April");

else if (month == 5) System.out.println("May");

else if (month == 6) System.out.println("June");

else if (month == 7) System.out.println("July");

else if (month == 8) System.out.println("August");

else if (month == 9) System.out.println("September");

else if (month == 10) System.out.println("October");

else if (month == 11) System.out.println("November");

else if (month == 12) System.out.println("December");

else if (month < 1) System.out.println("Oopps! Please enter number 1-12!");

else if (month > 12) System.out.println("Oopps! Please enter number 1-12!");

} // end loop

} // end method main

} // end class MonthNumber

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Edit java program user is prompted for new input
Reference No:- TGS01935561

Now Priced at $20 (50% Discount)

Recommended (99%)

Rated (4.3/5)