Java輸入年份和月份判斷多少天實(shí)例代碼
前言
本文主要介紹了如果通過輸入年份月份輸出天數(shù)的相關(guān)內(nèi)容,下面話不多說了,來一起看看詳細(xì)的介紹吧
示例代碼
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("請(qǐng)輸入年份");
int year = sc.nextInt();
System.out.print("請(qǐng)輸入月份");
int month = sc.nextInt();
if(month<0 || month>12 || year<0) {
System.out.println("請(qǐng)輸入合法的年月!");
}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天");
}
}
}
}
}
總結(jié)
到此這篇關(guān)于Java輸入年度和月份判斷多少天的文章就介紹到這了,更多相關(guān)Java輸入年度和月份判斷多少天內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Spring Boot + MyBatis Plus 高效開發(fā)實(shí)戰(zhàn)從入
本文將詳細(xì)介紹 Spring Boot + MyBatis Plus 的完整開發(fā)流程,并深入剖析分頁查詢、批量操作、動(dòng)態(tài) SQL、樂觀鎖、代碼優(yōu)化等實(shí)戰(zhàn)技巧,感興趣的朋友一起看看吧2025-04-04
Java導(dǎo)出oracle表結(jié)構(gòu)實(shí)例詳解
這篇文章主要介紹了 Java導(dǎo)出oracle表結(jié)構(gòu)實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-03-03
RabbitMq報(bào)錯(cuò)reply-code=406 reply-text=PRECONDITION_FAILED
這篇文章主要為大家介紹了RabbitMq報(bào)錯(cuò)reply-code=406 reply-text=PRECONDITION_FAILED分析解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12
SpringBean和Controller實(shí)現(xiàn)動(dòng)態(tài)注冊(cè)與注銷過程詳細(xì)講解
這篇文章主要介紹了SpringBean和Controller實(shí)現(xiàn)動(dòng)態(tài)注冊(cè)與注銷過程,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2023-02-02

