How to calculate no of days in a month? User to enter the no of the month. I have written a piece of code for the above, and want to know if its appropriate.
public class Exercise{
public static void main(String[] args) {
System.out.print("Input a month number:");
Scanner scan ;
int month = 1; int monthName = 1;
while(month < 12 && month > 0) {
scan = new Scanner(System.in);
monthName = scan.nextInt();
month= monthName-1;
DateFormat df = new SimpleDateFormat("MMM", Locale.US);
Calendar mycal = Calendar.getInstance();
mycal.set(Calendar.YEAR, 2017);
mycal.set(Calendar.MONTH, month);
int numDays = mycal.getActualMaximum(Calendar.DATE);
System.out.println(" The no of days in the month of is "+ " "+ numDays);
}
}
}