In: Computer Science
In a file called NumbersToMonths.java, write a program that:
For example: if the user enters 1, your program output should look EXACTLY like this:
Please indicate a month as an integer from 1 to 12: 1 January
import java.util.Scanner;
public class NumbersToMonths {
public static String getMonth(int num){
switch (num){
case 1:
return "January";
case 2:
return "February";
case 3:
return "March";
case 4:
return "April";
case 5:
return "May";
case 6:
return "June";
case 7:
return "July";
case 8:
return "August";
case 9:
return "September";
case 10:
return "October";
case 11:
return "November";
case 12:
return "December";
default:
return "";
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n;
System.out.print("Please indicate a month as an integer from 1 to 12: ");
n = scanner.nextInt();
String res = getMonth(n);
if(res.equals("")){
System.out.println("This number does not correspond to a month.");
}
else{
System.out.println(res);
}
}
}


