
The program will use the JOptionPane and ask the user to enter any number between 1 to 12.
Based on the input, then the program will show how many days in that month. For example if the user enters 1, the program will show â??The Month you entered is January and it has 31 daysâ??. The output will be shown in the JOptionpane.
NOTE:
[In this program use try and catch block to handle any unacceptable and invalid input from the user]

The program will use the JOptionPane and ask the user to enter any number between 1 to 12.
Based on the input, then the program will show how many days in that month. For example if the user enters 1, the program will show â??The Month you entered is January and it has 31 daysâ??. The output will be shown in the JOptionpane.
NOTE:
[In this program use try and catch block to handle any unacceptable and invalid input from the user]

import javax.swing.*;
import java.util.*;
import java.text.*;
class SectionB{
static String getMonthName(int m) {
String month = "invalid";
DateFormatSymbols dfs = new DateFormatSymbols();
String[] months = dfs.getMonths();
if (m >= 0 && m <= 11 ) {
month = months[m];
}
return month;
}
public static void main(String[] args){
int days=0;
String st=JOptionPane.showInputDialog(null,"Enter number between 1 and 12: ");
int num=Integer.parseInt(st);
switch(num){
case 1:
days=31;
break;
case 2:
String str=JOptionPane.showInputDialog(null,"Is this a leap year?");
if(str.equalsIgnoreCase("yes")){
days=29;
}
else{
days=28;
}
break;
case 3:
days=31;
break;
case 4:
days=30;
break;
case 5:
days=31;
break;
case 6:
days=30;
break;
case 7:
days=31;
break;
case 8:
days=31;
break;
case 9:
days=30;
break;
case 10:
days=31;
break;
case 11:
days=30;
break;
case 12:
days=31;
break;
default:
System.out.println("Invalid!");
System.exit(0);
}
JOptionPane.showMessageDialog(null,"The Month you entered is "+getMonthName(num-1)+" and it has "+days+" days");
}
}