zoukankan      html  css  js  c++  java
  • java 判断某一天是当年的哪一天

    题目:输入年份,月份,日,判断这一天是这一年的第几天?(闰年的2月份为29天,平年为28天)

    public class Runnian {
    
        /**
         * 能被4整除且不能被100整除或者能被400整除的年份为闰年
         * @param args
         */
        public static void main(String[] args) {
            System.out.println("请输入年,月,日");
            Scanner sc1=new Scanner(System.in);
            int year=sc1.nextInt();
            Scanner sc2=new Scanner(System.in);
            int month=sc2.nextInt();
            Scanner sc3=new Scanner(System.in);
            int day=sc3.nextInt();
            int totalDay=0;
            for(int i=1;i<month;i++){
                totalDay+=getMonthDay(year,i);
                System.out.println("总天数为"+totalDay);
            }
            System.out.println("总天数为"+(totalDay+day));
            
        }
        public static int getMonthDay(int year,int month){
            boolean flag=isRunnian(year);
            if(month==2){
                if(flag==true){
                return 29;
                }else{
                    return 28;
                }
            }else if(month==4||month==6||month==9||month==11){
                return 30;
            }else{
                return 31;
            }
        }
        public static boolean isRunnian(int year){
            if((year%4==0&&year%100!=0)||(year%400==0)){
                return true;
            }else{
                return false;
            }
            
        }
    }
  • 相关阅读:
    Apache POI 示例
    使用wsimport生成webservice客户端代码
    监听器
    @WebFilter注解
    事务
    k8s的deployment应用
    k8s 组件架构
    使用kubeadm安装kubernetes1.12.1
    轻量级批量管理工具pssh
    使用Bind服务配置DNS服务器
  • 原文地址:https://www.cnblogs.com/tjlgdx/p/5985806.html
Copyright © 2011-2022 走看看