Note: Donot mark it duplicate, I know it is duplicate question but I didn't get help from it.
I want to calculate Number Of Days in a month of particular year. I read this and but it is NOT working fine. I tried following
public class NumOfDays {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter month: ");
int month = input.nextInt();
System.out.print("Enter year: ");
int year = input.nextInt();
Calendar mycal = new GregorianCalendar(year, month, 1);
System.out.println("Number of days are: " + mycal.getActualMaximum(Calendar.DAY_OF_MONTH));
}
}
My Console is
Enter month: 2
Enter year: 2000
Number of days are: 31 /// Wrong
and
Enter month: 10
Enter year: 1999
Number of days are: 30 // Correct
I know that there are one other method i.e. to calculate it manually, but I want to do it like above. Please let me know if I am doing anything wrong.
P.S: I am using JAVA-8.