题解 | #计算日期到天数转换#

计算日期到天数转换

https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded

public class Main{
public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNext()){ String time = in.nextLine(); String[] s = time.split(" "); int[] arr = new int[s.length]; for (int i = 0; i < s.length; i++) { arr[i] = Integer.parseInt(s[i]);
        } int[] mouthDay = {31,28,31,30,31,30,31,31,30,31,30,31}; if (checkYear(arr[0])){ mouthDay[1] = 29;
        } int count = 0; for (int i = 0; i < arr[1]-1; i++) {
            count = mouthDay[i] +count;
        }
        count = count + arr[2]; System.out.println(count);
    }
} public static boolean checkYear(int year){ if (year%400 == 0 ){ return true;
    } if (year%4 == 0 && year % 100 != 0){ return true;
    } return false;
}


}
全部评论

相关推荐

2025-12-23 18:51
中南大学 Java
唉又萌混过关:是不是那种收钱盖实习章的机构?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务