首页 > 代码库 > 显示某个月的天数

显示某个月的天数

import java.util.Scanner;public class Days {    public static void main(String[] args){        Scanner input = new Scanner(System.in);        int day = 0;        System.out.println("请输入年份:");        int year = input.nextInt();        System.out.println("请输入月份:");        int month = input.nextInt();        if (0 < month && month < 12){            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){                day = 31;            }            else if (month == 4 || month == 6 || month == 9 || month == 11){                day = 30;            }            else {                if (year % 4 == 0 && year % 100 != 0 || year % 400 ==0){                    day = 29;                }                else{                    day = 28;                }            }            System.out.println(year + "年 " +month + "月有" + day + "天");        }        else{            System.out.println("请输入1-12");        }                    }}

输入年份和月份,显示这个月的天数。