+ 1
Someone to help me? I try to run my code but it doesn't and I don't see where is the bugg..
Go to my profile and see the code "We The Human"
1 Odpowiedź
+ 6
Comparing strings with == can get unexpected results when taking input. Keep in mind what == actually does (compares reference for Objects).
Two ways to fix this:
You can use .equals("w") instead of ==.
Example/
if(choice.equals("w"))
{
}
Or
You can take the input as a char, then compare it with the character 'w'. (Same things for 'm').
Example/
char choice = sc.next().charAt(0);
if(choice == 'w')
{
}