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

后端 未结 6 1506
野的像风
野的像风 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:25

    You should use && (AND) instead of || (OR) in your conditions.

    Try else if (userxp >=level1xp && userxp using in all of your else if statements.

    In your code, the execution stops after the first else statement, which is true.

            if (userxp <=level1xp){
                userlevel=1;
            }else if (userxp 

    EDIT: as pointed out in the owther answers, you do not need the first condition for the lower bound of the level since it is already satisfied by the previous else statement.

提交回复
热议问题