懂得来看看哪里错误啊。谢谢

来源:百度知道 编辑:UC知道 时间:2024/05/28 14:09:27
要求用多重if结构。我写完之后,只能表示出闰年,不能表示平年。例如:输入年份:2009(平年到这里就没了)但是闰年能全部显示,例如:输入年份:2008
2008年是闰年
输入月份:3
2008年3月的天数是31天

import java.util.*;
public class Shangji5 {

public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.print("输入年份:");
int year=input.nextInt();
if ((year%4==0&&year%100!=0)||(year%400==0)){
System.out.println(year+"年是闰年");
System.out.print("输入月份:");
int month=input.nextInt();
if (month==1||month==3||month==5||month==7||month==8||month==10||month==12){
System.out.println(year+"年"+month+"月的天数是31天");
}else if(month==2&&year%400==0){
System.out.println(year+"年"+month+"月的天数是29天");
} else if(month==2&&year%400==0){
System.out.println(year+"年"+month+"月的天数是28天");
}else if(mon

import java.util.*;

public class Shangji5 {

public static void main(String[] args) {
int[] months = new int[]{31,28,31,30,31,30,31,31,30,31,30,31};
Scanner input = new Scanner(System.in);
System.out.print("输入年份:");
int year = input.nextInt();
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
System.out.println(year + "年是闰年");
months[1] = 29;
}else{
System.out.println(year + "年不是闰年");
}
System.out.print("输入月份:");
int month = input.nextInt();
System.out.println(year+"年"+month+"月的天数是"+months[month-1]+"天");
}
}

你这里光处理闰年了。也没处理平年啊……
改后:

import java.util.*;

public class Test{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.print("输入年份:");
int year=input.nextInt();