import java.util.*;
public class in{
public static void main(String[] args){
System.out.println("请输入一个年份:");
Scanner input=new Scanner(System.in);
int year=input.nextInt();
/*
判断是否是瑞年还是平年(瑞年能被4整除并且不能被100整除||能
被400整除的年份是瑞年)
*/
if(year%4==0){
if(year%100!=0){
System.out.println(year+"这年是瑞年");
}
}
if(year%400==0){
System.out.println(year+"这年是瑞年");
}
else{
System.out.println(year+"这年是平年");
}
}
}

解决方案 »

  1.   

    因为你第二个if(year%400==0)的原因
      

  2.   

    import java.util.*;public class in {
    public static void main(String[] args) {
    System.out.println("请输入一个年份:");
    Scanner input = new Scanner(System.in);
    int year = input.nextInt();
    /*
     * 判断是否是瑞年还是平年(瑞年能被4整除并且不能被100整除||能 被400整除的年份是瑞年)
     */
    if (year % 4 == 0) {
    if (year % 100 != 0||year % 400 == 0) {
    System.out.println(year + "这年是瑞年");
    }else {
    System.out.println(year + "这年是平年");
    }
    } else {
    System.out.println(year + "这年是平年");
    }
    }
    }闰年怎么算的,搞忘了,不知道是不是这么算的。。
      

  3.   

    第二个if(year%400==0)用404时不是不成立吗?应该不会输出来啊
      

  4.   

    首先注意错别字。
    闰年
    第二,你的错误:public static void main(String[] args) {
    System.out.println("请输入一个年份:");
    Scanner input = new Scanner(System.in);
    int year = input.nextInt();
    /*
     * 判断是否是瑞年还是平年(瑞年能被4整除并且不能被100整除||能 被400整除的年份是瑞年)
     */
    if (year % 4 == 0) {
    if (year % 100 != 0) {
    System.out.println(year + "这年是瑞年");
    }
    }
    if (year % 400 == 0) {
    System.out.println(year + "这年是瑞年");
    } else {
    //错误就在这里,不能被400整除的书并不一定不是闰年,比如404不能被400整除,但一样是闰年
    System.out.println(year + "这年是平年");
    }
    }
      

  5.   

    你们测试下,我改了下,暂时没发现错误public static void main(String[] args) {
    System.out.println("请输入一个年份:");
    Scanner input = new Scanner(System.in);
    int year = input.nextInt();
    /*
     * 判断是否是瑞年还是平年(瑞年能被4整除并且不能被100整除||能 被400整除的年份是瑞年)
     */
    if (year % 4 == 0) {
    if (year % 100 != 0&&year % 400 != 0) {
    System.out.println(year + "这年是瑞年");

    }else{
    if (year % 400 == 0) {
    System.out.println(year + "这年是瑞年");
    } else {
    //错误就在这里,不能被400整除的书并不一定不是闰年,比如404不能被400整除,但一样是闰年
    System.out.println(year + "这年是平年");
    }
    }

    }

    }
      

  6.   

    LZ代码执行了2个if-else 第一个为闰年 true 第二个为平年 false 故有2个输出
    根据判断逻辑 true||false=true 得出404是闰年
    LZ if-else的条件写的比较冗余
      

  7.   

    懂了原来是else跟的是第二个if一起的,没跟第一个搞在一起
      

  8.   

    楼主的第二个if应该放在第一个if的else里边if( (year%4 == 0 && year%400 !=0) || (year%400 == 0) ){
       System.out.print("闰年");
    }
    else{
    System.out.print("非闰年");
    }
      

  9.   

    你这代码后面的个if else与前面的if无关,so第一个if能进去,后面的else也能走
      

  10.   

    其实很简单. 把你的if(year%400==0)改成else if(year%400==0)就行了. 不满足上面两个条件才是平年.
    import java.util.*;
    public class in {
    public static void main(String[] args) {
    System.out.println("请输入一个年份:");
    Scanner input = new Scanner(System.in);
    int year = input.nextInt();
    /*
     * 判断是否是瑞年还是平年(瑞年能被4整除并且不能被100整除||能 被400整除的年份是瑞年)
     */
    if (year % 4 == 0) {
    if (year % 100 != 0) {
    System.out.println(year + "这年是瑞年");
    }
    }else if (year % 400 == 0) {
    System.out.println(year + "这年是瑞年");
    } else {
    System.out.println(year + "这年是平年");
    }
    }
    }