+ 3

What is wrong with the java code?

I made the following code last night but the output always says that my input is not correct as in the the last else statement of the code https://code.sololearn.com/c3x1WpOsuSIm/?ref=app

14th Jan 2018, 8:11 PM
Richard Cofie
Richard Cofie - avatar
4 ответов
+ 3
In Java for comparing strings you may not use == because then the program Will compare the references and not the actual value of the string. Instead use the .equals() method, for example pPlay.equals("r")
14th Jan 2018, 8:27 PM
Jente
+ 4
thanks!! it worked!
14th Jan 2018, 8:33 PM
Richard Cofie
Richard Cofie - avatar
+ 3
well I thought of using char... but last time I used it it didn't work- must have made a mistake-, which brought me to think it wouldn't work until you said so
14th Jan 2018, 8:36 PM
Richard Cofie
Richard Cofie - avatar
+ 1
If you need only one character, then don't use a String, just use a char data type. And compare them using single quotes (' '). May be it'll solve the prblm. May be not. Just try!
14th Jan 2018, 8:31 PM
Harjeet Singh
Harjeet Singh - avatar