Ask coding questions

← Back to all posts
How do i get the option to only run if the options number is put in?
Ardin16

What i have right now is:

If i do:

then it will run but all of them will run with the given inputs. I know that's because == is setting the choice from the original input to the number after it and the code i have now it won't run since it can't convert string to boolean and i'm not sure how to fix it

Voters
Ardin16
Comments
hotnewtop
EpicGamer007

if you want to compare strings, you have to use .equals() and not == so change it to if (choice.equals("1")) { System.out.println(one + two); }, etc