java日期类的封装与调用

import java.io.*;

public class 日期类

{  /**   * @param args   */

 public static void countday(String[] args) throws IOException

{

  // TODO Auto-generated method stub

  int year,month,date,i,day=0;  

 String str;  

 BufferedReader buf;  

 buf=new BufferedReader(new InputStreamReader(System.in));  

 System.out.println("输入一个年份");  

 str=buf.readLine();  

 year=Integer.parseInt(str);  

 System.out.println("输入一个月份");  

 str=buf.readLine();

  month=Integer.parseInt(str);

  System.out.println("输入一个日期");

  str=buf.readLine();

  date=Integer.parseInt(str);  

 for(i=1;i<month;i++)  

 {   

 day+=countDay(i,year);

      }

  day+=date;   

System.out.println(day);

 }  

 static int countDay(int month,int year)  

 {

   int count=0;

   switch(month)  

  {    

case 1:  

  case 3:    

case 5:    

case 7:

   case 8:

   case 10:  

  case 12:    

 count=31;     

break;    

case 4:    

case 6:    

case 9:    

case 11:     

count=30;     

break;    

case 2:    

 if(year%4==0&&year%100!=0||year%400==0)      

count=29;   

  else      

count=2;  

  }      

 return count;  

}

}

import java.io.*;

public class 日期类的调用输出

{

 /**   * @param args   */  

public static void main(String[] args) throws IOException

{   

// TODO Auto-generated method stub   

日期类.countday(args);  

}

}