// Compute the number of days in a user-specified month 

import java.io.*;

public class DaysInMonth {
	// main(): application entry point 
	public static void main(String[] args) throws IOException {
		final int JANUARY = 1;      final int JULY = 7;
		final int FEBRUARY = 2;     final int AUGUST = 8;
		final int MARCH = 3;        final int SEPTEMBER = 9;
		final int APRIL = 4;        final int OCTOBER = 10;
		final int MAY = 5;          final int NOVEMBER = 11;
		final int JUNE = 6;         final int DECEMBER = 12;

		final int CALENDAR_START = 1582;

		// get an input reader 
		BufferedReader stdin = new BufferedReader(
			new InputStreamReader(System.in));

		// get date information of interest 
		System.out.println("");
		System.out.print("Enter year: ");
		int year = Integer.parseInt(stdin.readLine());
		System.out.print("Enter month: ");
		int month = Integer.parseInt(stdin.readLine());

		// validate input 
		if ((year < CALENDAR_START) || (month < 1) || (month > 12)) {
			System.out.println("Bad request: " + year + " " 
					+ month);
			System.exit(1);
		}

		// determine whether year is a leap year 
		boolean isDivisibleBy4 = (year % 4) == 0;
		boolean isDivisibleBy100 = (year % 100) == 0;
		boolean isDivisibleBy400 = (year % 400) == 0;

		boolean isLeapYear = isDivisibleBy4
			&& ((! isDivisibleBy100) || isDivisibleBy400);

	// use month and year information to determine number of days 
	int days;
	switch (month) {
		case JANUARY: case MARCH: case MAY: case JULY: case AUGUST: 
		case OCTOBER: case DECEMBER:
			days = 31;
			break;
		case APRIL: case JUNE: case SEPTEMBER: case NOVEMBER:
			days = 30;
			break;
		case FEBRUARY: 
			days = isLeapYear ? 29 : 28;
			break;
		default:
			days = 0;
	}

	System.out.println("");
	System.out.println("Month " + month + " in year " + year
									+ " has " + days + " days");
	}
}


