Create a string array by populating the month name. Now accept the month name from user and match it to the array. If match it then print the (index+1) as a month number.
public class MonthNameToNumber
{
public static void main(String []args)
{
String []months={"January","Februry","March","April","May","June","July","August","September","October","November","December"};
Scanner sc=new Scanner(System.in);
System.out.print("Enter month name : ");
String mon=sc.next();
for(int i=0;i<months.length;i++)
{
if(mon.toLowerCase().equals(months[i].toLowerCase()))
{
System.out.println("Your Month number is " + (i+1));
break;
}
}
}
}
Enter month name : january
Your Month number is 1
Enter month name : May
Your Month number is 5