星空网 > 软件开发 > Java

Java程序设计之算出一年第多少天

  可以直接拷贝运行。

package year;import java.util.Scanner;public class year {  public static void main(String[] args) {    // TODO Auto-generated method stub    year y = new year();    y.fun();  }    public void fun(){    String str = shuru();    int year = Integer.parseInt(str.split(" ")[0]);    int month = Integer.parseInt(str.split(" ")[1]);    int day = Integer.parseInt(str.split(" ")[2]);    jisuan(year,month,day);  }    private String shuru(){    System.out.print("输入年月日中间以空格间隔:");    Scanner s = new Scanner(System.in);    return s.nextLine();  }    private void jisuan(int year, int month,int day){    int i = 0;    int j = 0;    //是闰年    if(year%400 == 0||year%4==0&&year%100!=0){      switch(month){      case 12: i+=31;      case 11: i+=30;      case 10: i+=31;      case 9: i+=30;      case 8: i+=31;      case 7: i+=31;      case 6: i+=30;      case 5: i+=31;      case 4: i+=30;      case 3: i+=31;      case 2: i+=28;      case 1: i+=31;      }      if(month == 1||month == 3||month == 5||month == 7||month == 8||month == 10||month == 12){        j = 31 - day;        System.out.println(i-j);      }else if(month == 2){        j = 28 - day;        System.out.println(i-j);      }else{        j = 30 - day;        System.out.println(i - j);      }    }else{      switch(month){      case 12: i+=31;      case 11: i+=30;      case 10: i+=31;      case 9: i+=30;      case 8: i+=31;      case 7: i+=31;      case 6: i+=30;      case 5: i+=31;      case 4: i+=30;      case 3: i+=31;      case 2: i+=29;      case 1: i+=31;      }      if(month == 1||month == 3||month == 5||month == 7||month == 8||month == 10||month == 12){        j = 31 - day;        System.out.println(i-j);      }else if(month == 2){        j = 28 - day;        System.out.println(i-j);      }else{        j = 30 - day;        System.out.println(i - j);      }    }  }}

  比如输入:1994 3 28

  输出:88

  1994年的第88天。




原标题:Java程序设计之算出一年第多少天

关键词:JAVA

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

德国VAT注册流程详解快速掌握全部程序:https://www.kjdsnews.com/a/1376741.html
德国VAT注册流程详解:https://www.kjdsnews.com/a/1376742.html
德国VAT注册流程指南让你快速搞定:https://www.kjdsnews.com/a/1376743.html
德国VAT注册流程指南一步一步走向成功:https://www.kjdsnews.com/a/1376744.html
德国VAT注册流程指南一步一步搞定:https://www.kjdsnews.com/a/1376745.html
南美洲国家和地区单证最新规定:https://www.kjdsnews.com/a/1376746.html
请问西安及周边5日游怎么安排?:https://www.vstour.cn/a/364173.html
图策全国免景点门票 预订景区门票优惠:https://www.vstour.cn/a/364174.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流