zoukankan      html  css  js  c++  java
  • 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);  

    }

    }

  • 相关阅读:
    (第九周)视频发布及git统计报告
    (第九周)团队项目16
    (第九周)团队项目15
    (第九周)团队项目14
    C# 中请求数据方式
    C#中Json和List/DataSet相互转换
    C#枚举注释实例
    C#常用简单线程实例
    C#动态多线程实例
    MySql中文乱码
  • 原文地址:https://www.cnblogs.com/iris-yx/p/3417149.html
Copyright © 2011-2022 走看看