用if-else 写year

    xiaoxiao2022-07-02  107

    题目: 判断某年是否为闰年:用户从控制台输入需要判断的年份值,由程序使用if-else判断该年是否为闰年,并将判断结果输出到控制台

    package cn.tendu.day03; import java.util.Scanner; public class IfElseIfDemo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int year,month = 0; System.out.println("输入年份:"); Scanner sc1 = new Scanner(System.in); System.out.println("输入月份:"); Scanner sc11 = new Scanner(System.in); year=sc11.nextInt(); month=sc11.nextInt(); if(year % 4 == 0 && year % 100 != 0){ System.out.println("该年是闰年"); } else{ System.out.println("该年是平年"); } if(year % 4 == 0 && year % 100 != 0 && month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { System.out.println(year+"年"+month+"月有31天"); } else if(month==4||month==6||month==9||month==11) { System.out.println(year+"年"+month+"月有30天"); } else if (year % 4 == 0 && year % 100 != 0 && month == 2){ System.out.println(year+"年"+month+"月有29天"); } else { System.out.println(year+"年"+month+"月有28天"); } } }
    最新回复(0)