如果是其他声明

时间:2017-04-10 08:36:23

标签: java if-statement

想要使用此代码搜索1950-2050之间的日期并找出什么时候没有发生,世界杯,奥运会或您撰写的信息与任何日期都不匹配。

因此,当1950年至1950年之间的数字除以4时,就会发生这种情况。而WC就发生在2002年(2004年WC)2006年的OL之间。

然后我们在1950 - 2050年间没有OL / WC的日期,那一年没有发生任何事情。最后如果你输入700就应该说最后一个。

Scanner input = new Scanner(System.in);

System.out.println("Write year between 1950-2050: ");
int keyboard = input.nextInt();
int OL = (keyboard);
int WC = (keyboard);
int nothingspec = (keyboard);
int instru = (keyboard);

if(nothingspec) {

 System.out.println("This year nothing special happened.");

}

else if(OL) { 

 System.out.println("Yes this year it the olympic games. ");

}      

else if(WC) { 

    System.out.println("Yes this year it was a world cup in soccer.");

}     

else(instru) {

    System.out.println("Your instructions were wrong please try again.");
}

input.close();

1 个答案:

答案 0 :(得分:0)

据我所知,它应该是这样的

         System.out.println("Write year between 1950-2050: ");
         int keyboard = input.nextInt();
         int OL = (keyboard);
         int WC = (keyboard);
         int nothingspec = (keyboard);
         int instru = (keyboard);
         boolean blOL = false;
         boolean blWC = false;
         //this occurs whenever the number can be divided by 4
         if(keyboard>=1950&&keyboard<=2050){
            if(OL%4==0) { 

             System.out.println("Yes this year it the olympic games. ");
            blOL=true;
            }      
            //This will happen every time the date can be divided to 2 so as               you said 2002, 2004, 2006 and so on. 
            else if(WC%2==0) { 

                System.out.println("Yes this year it was a world cup in   soccer.");
            blWC = true;
            }
            //This is when nothing has happend.     
            else if(blOL==false && blWC==false) {

             System.out.println("This year nothing special happened.");

            }
            else{

                System.out.println("Your instructions were wrong please try again.");
            }
          }
          else{

                System.out.println("Your instructions were wrong please try again.");
            }


    input.close();

请尝试这个并告诉我这是否是你需要的。