Java – if the else statement has four results, but only two seem to work

So I'm studying my first project on programming Never tried any programming I want it to be able to choose between four different results and the default function, but it seems that it can only choose between the if statement and the second if statement What did I do wrong?

private void userStandby () {                                                             

    System.out.println("What do you want to set your membershipstatus to");                       
    System.out.println("1) Active \n2) Standby");                                              
    int newchange = input.nextInt();                                                          

    ((Medlem) currentUser).setStatus(newchange);                                             

    if (((Medlem) currentUser).getStatus() == 1 && newchange == 1) {                         
        System.out.println("Your membership is already active");                                                                                                                
    } else if (((Medlem) currentUser).getStatus() == 1 && newchange == 2)  {                  
        System.out.println("Your membership is Now on standby");                              
    } else if (((Medlem) currentUser).getStatus() == 2 && newchange == 2) {                   
        System.out.println("Your membership is already on standby");                      
    } else if (((Medlem) currentUser).getStatus() == 2 && newchange == 1) {                    

        System.out.println("Your membership is Now active");                                   
   } else                                                                                     
        System.out.println("Please write 1 or 2");                                  

   userStandby();                                                                           

}

Solution

((Medlem) currentUser).setStatus(newchange);
((Medlem) currentUser).setStatus(newchange);

Means ((medlem) currentuser) Getstatus() = = newchange, so of course you can only take two branches - one branch with both branches equal to 1 and two branches with two branches equal to 2 respectively

Maybe your intention is in if else if -- After the else statement, call setStatus..

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>