一个月中的日期 package nameyu; import java.util.Scanner;public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.print("Enter a year:"); int year=input.nextInt(); Scanner iput=new Scanner(System.in); System.out.print("Enter a month:"); String month=iput.nextLine(); char ch1=month.charAt(0); char ch2=month.charAt(1); char ch3=month.charAt(2); if(ch1=='J'&&ch2=='a'&&ch3=='n'){ System.out.println("Jan "+year+" has 31 days"); } else if(ch1=='F'&&ch2=='e'&&ch3=='b'){ if((year%4==0&&year%100!=0)||(year%400==0)){ System.out.println("Feb "+year+" has 29 days"); }else System.out.println("Feb "+year+" has 28 days"); } else if(ch1=='M'&&ch2=='a'&&ch3=='r'){ System.out.println("Mar "+year+" has 31 days"); } else if(ch1=='A'&&ch2=='p'&&ch3=='r'){ System.out.println("Apr "+year+" has 30 days"); } else if(ch1=='M'&&ch2=='a'&&ch3=='y'){ System.out.println("May "+year+" has 31 days"); } else if(ch1=='J'&&ch2=='u'&&ch3=='n'){ System.out.println("Jun "+year+" has 30 days"); } else if(ch1=='J'&&ch2=='u'&&ch3=='l'){ System.out.println("Jul "+year+" has 31 days"); } else if(ch1=='A'&&ch2=='u'&&ch3=='g'){ System.out.println("Aug "+year+" has 31 days"); } else if(ch1=='S'&&ch2=='e'&&ch3=='p'){ System.out.println("Sep "+year+" has 30 days"); } else if(ch1=='O'&&ch2=='c'&&ch3=='t'){ System.out.println("Oct "+year+" has 31 days"); } else if(ch1=='N'&&ch2=='o'&&ch3=='v'){ System.out.println("Nov "+year+" has 30 days"); } else if(ch1=='D'&&ch2=='e'&&ch3=='c'){ System.out.println("Dec "+year+" has 31 days"); } } }
|