zoukankan      html  css  js  c++  java
  • java实现输入日期,输出是该年的第几天

    import java.io.*;

    public class countday {

     /**   * @param args   */  

    public static void main(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;  

    }

    }

  • 相关阅读:
    Warning:mailcious javascript detected on this domain来由
    CSS盒模型重新理解篇
    sublime生产力提升利器
    Aptana studio 3前端开发编辑器推荐
    Provides PHP completions for Sublime Text
    关于google电子地图跟卫星地图位置不重合
    无名前端库
    npm 编写cli
    webpack.merge
    ExcelDNA UDF 攻略
  • 原文地址:https://www.cnblogs.com/iris-yx/p/3378306.html
Copyright © 2011-2022 走看看