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;  

    }

    }

  • 相关阅读:
    AJAX基础
    DOM事件机制(事件捕获和事件冒泡和事件委托)
    http协议
    DOM实战-js todo
    python常见面试题
    jQuery快速入门
    三级菜单
    购物车
    员工信息表
    random模块
  • 原文地址:https://www.cnblogs.com/iris-yx/p/3378306.html
Copyright © 2011-2022 走看看