import javax.swing.JOptionPane;
public class Numnumdays {
public static void main(String[] args) {
int numdays = 0, month, year;
String monthname = "";
String input;
input =JOptionPane.showInputDialog(null,"Please enter the year","Year",JOptionPane.QUESTION_MESSAGE)
year = Integer.parseInt(input);
input = JOptionPane.showInputDialog(null,"Please enter the month of the year","Month",JOptionPane.QUESTION_MESSAGE);
month = Integer.parseInt(input);
switch (month){
case 1: numdays = 31;
monthname = "January";
break;
case 2:
if ((year % 4 == 0 && year % 100 != 0) year % 400 == 0)
numdays = 29;
else
numdays = 28;
monthname = "February";
break;
case 3: numdays = 31;
monthname = "March";
break;
case 4 : numdays = 30;
monthname = "April";
break;
case 5: numdays = 31;
monthname = "May";
break;
case 6: numdays = 30;
monthname = "June";
break;
case 7: numdays = 31;
monthname = "July";
break;
case 8: numdays = 31;
monthname = "August";
break;
case 9: numdays = 30;
monthname = "September";
break;
case 10: numdays = 31;
monthname = "October";
break;
case 11: numdays = 30;
monthname = "November";
break;
case 12: numdays = 31;
monthname = "December";
}
JOptionPane.showMessageDialog(null,"In " + monthname + " " + year + ", there are " + numdays + " numdays","No. of numdays",JOptionPane.INFORMATION_MESSAGE);
} // end main
} // end class
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment