Skip to content

Instantly share code, notes, and snippets.

@Yurlov
Created June 30, 2016 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yurlov/23ab1193eaf4648feeb3682779be2abd to your computer and use it in GitHub Desktop.
Save Yurlov/23ab1193eaf4648feeb3682779be2abd to your computer and use it in GitHub Desktop.
Prog.kiev.ua
public class MonthSample {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int month = getScan(in);
checkMonth(month);
getMonth(month);
in.close();
}
private static void checkMonth(int month) {
if (month<1||month>12){
throw new IllegalArgumentException("illegal month");
}
}
private static int getScan(Scanner in){
System.out.println("Enter number of month(1 - 12): ");
return in.nextInt();
}
private static void getMonth(int month) {
switch (month){
case 1:
System.out.println("January");
break;
case 2:
System.out.println("February");
break;
case 3:
System.out.println("March");
break;
case 4:
System.out.println("April");
break;
case 5:
System.out.println("May");
break;
case 6:
System.out.println("June");
break;
case 7:
System.out.println("July");
break;
case 8:
System.out.println("August");
break;
case 9:
System.out.println("September");
break;
case 10:
System.out.println("October");
break;
case 11:
System.out.println("November");
break;
case 12:
System.out.println("December");
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment