Java level calculator if statement returning the wrong value (Newbie)

后端 未结 6 1459
野的像风
野的像风 2021-01-21 09:48

i\'m learning some Java and decided to do something simple but it keeps returning the wrong value... i don\'t know why i\'m sure there something that my untrained eye isn\'t pic

6条回答
  •  臣服心动
    2021-01-21 10:09

    You condition is wrong use && instead of ||. Because in your condition whenever the first part of the condition is true the condition becomes true.

    import java.util.Scanner;
    import java.lang.*;
    
    public class HelloWorld{
    
        public static void main(String args[]){
            int userlevel = 0;
            int userxp=12;
            int level1xp=0, level2xp=1, level3xp=10, level4xp=15, level5xp=25;
            int level1=1, level2=2, level3=3, level4=4, level5=5;
    
            if (userxp <=level1xp){
                userlevel=1;
            }else if (userxp >=level1xp && userxp = level3xp &&  userxp =level3xp &&  userxp 

提交回复
热议问题