How to create in Java solution just with "switch and if" such an input "January", "january", JANUARY", janUARY" and any other combination of case is treated as "January" and in all cases prints out 1. I did program, but it is working just with the same input words, maybe exist a trick to resolve that.
import java.util.Scanner;
public class nameMonth
{
public static void main(String[] args)
{
String month;
int nrMonth;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter a month");
month = keyboard.nextLine();
switch (month)
{
case "January":
System.out.println("Your month is January");
nrMonth = 1;
break;
case "February":
System.out.println("Your month is February");
nrMonth = 2;
break;
case "March":
System.out.println("Your month is March");
nrMonth = 3;
break;
case "April":
System.out.println("Your month is April");
nrMonth = 4;
break;
case "May":
System.out.println("Your month is May");
nrMonth = 5;
break;
case "June":
System.out.println("Your month is June");
nrMonth = 6;
break;
case "July":
System.out.println("Your month is July");
nrMonth = 7;
break;
case "August":
System.out.println("Your month is August");
nrMonth = 8;
break;
case "September":
System.out.println("Your month is September");
nrMonth = 9;
break;
case "October":
System.out.println("Your month is October");
nrMonth = 10;
break;
case "November":
System.out.println("Your month is November");
nrMonth = 11;
break;
case "December":
System.out.println("Your month is December");
nrMonth = 12;
break;
default:
System.err.println("Your month is wrong");
break;
}
}
}