Month of the year checker
import java.util.Scanner;
public class months_of_the_year {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter a number ranging from 1- 12 to know the corresponding month");
int range = input.nextInt();
while (range <1 || range >12){ // keeps the user in this loop as long as the condition remain true//
System.out.println("You have enter an invalid number");
System.out.println("Enter a number ranging from 1- 12 to know the corresponding month");
range = input.nextInt();
}
switch (range){ // This checks the input from the user and print the condition that meets the corresponding case
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");
case 10:
System.out.println("October");
case 11:
System.out.println("November");
case 12:
System.out.println("December");
break;
}
}
}
Comments
Post a Comment