Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
1
Indexable
Never
import java.util.*;

public class Main {
    public static void main(String[] args) throws Throwable {
        Scanner sc = new Scanner(System.in);
		int month = sc.nextInt();
		int	year = sc.nextInt();

		int leap = leapYear(year); // Calling leapYear method.
		if(month == 2){
			if(year == leap){
				System.out.println("29");
			}
			else{
				System.out.println("28");
			}
		} 
		else{
			switch(month){
				case 1 : System.out.println("31");
					break;
				case 3 : System.out.println("31");
					break;
				case 4 : System.out.println("30");
					break;
				case 5 : System.out.println("31");
					break;
				case 6 : System.out.println("30");
					break;
				case 7 : System.out.println("31");
					break;
				case 8 : System.out.println("31");
					break;
				case 9 : System.out.println("30");
					break;
				case 10 : System.out.println("31");
					break;
				case 11 : System.out.println("30");
					break;
				case 12 : System.out.println("31");
					break;
				default : System.out.println("Enter valid month");		
			}
		}
		
    }

	public static int leapYear(int y) {
		if(y % 4 == 0){
			if(y % 100 != 0){
				return 1;
			}
			else if(y % 400 == 0){
				return 1;
			}
		    else{
				return 0;
			}
		}
		else{
			return 0;
		}
	}
}