import java.util.*;
class Ch2Q12
{
public static void main(String[] args)
{
Scanner kbd = new Scanner (System.in);
System.out.print("Enter the month no: ");
int mno = kbd.nextInt();
switch(mno)
{case 1:case 3: case 5: case 7: case 8 : case 10 : case 12:
System.out.println("No of days are 31"); break;
case 4: case 6: case 9: case 11:
System.out.println("No of days are 30"); break;
case 2: System.out.print("Enter the year: ");
int yr = kbd.nextInt();
if(leapyr(yr))
System.out.println("No of days are 29");
else System.out.println("No of days are 28");break;
default: System.out.println("Are you Crazy\n");
}
}
static boolean leapyr(int yr)
{if(yr%4 == 0)
if(yr < 1582)
return true;
else if(yr%100 == 0)
if(yr % 400 == 0)
return true;
else return false;
else return true;
else return false;
}
}
No comments:
Post a Comment