java判断输入月份_Java输入年份和月份判断多少天实例代码
前言
本文主要介紹了如果通過輸入年份月份輸出天數的相關內容,下面話不多說了,來一起看看詳細的介紹吧
示例代碼
package com.ambow.www.ch03;
import java.util.Scanner;
public class Day {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("請輸入年份");
int year = sc.nextInt();
System.out.print("請輸入月份");
int month = sc.nextInt();
if(month<0 || month>12 || year<0) {
System.out.println("請輸入合法的年月!");
}else {
switch(month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:System.out.println("31天");break;
case 4:
case 6:
case 9:
case 11:System.out.println("30天");break;
}
if((year%100!=0&&year%4==0)||year%400==0) {
if(month==2) {
System.out.println("29天");
}
}else {
if(month==2) {
System.out.println("28天");
}
}
}
}
}
總結
到此這篇關于Java輸入年度和月份判斷多少天的文章就介紹到這了,更多相關Java輸入年度和月份判斷多少天內容請搜索聚米學院以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持聚米學院!
總結
以上是生活随笔為你收集整理的java判断输入月份_Java输入年份和月份判断多少天实例代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 几何画板手机版_运用几何画板解决动点最值
- 下一篇: java通信项目_Java项目中的多线程