23 June, 2012

Find How Many Days in given Month


import java.util.*;
public class Fallswitchyear
{
public static void main(String[] args)
{
Scanner s=new Scanner (System.in);
System.out.printf("Enter Month no. -: ");
int n=s.nextInt();
if(n<1||n>12)
{
System.out.printf("Invalid Month");
}
switch(n)
{
case 4:
case 6:
case 9:
case 11:    System.out.println("Month have 30 Days");
    break;
case 2:    System.out.printf("Enter Year -: ");
    int y=s.nextInt();
    if((y%400==0)||(y%4==0 && y%100!=0))
    System.out.println("Month have 29 Days");
    else
    System.out.println("Month have 28 Days");
    break;
default :    System.out.println("Month have 31 Days");
    break;
}
}
}

No comments:

Post a Comment

Thank You !