0
equals() on incompatible types
So the problem is i get this error : equals() on incompatible types if (YE.equals("Exam")){ System.out.println(YE.nextLine()); HEO.Salad("S");} what should i do ? https://code.sololearn.com/cYA002DZEcVw
19 Respostas
+ 3
Pretty margaret What i said is that you cannot compare a Scanner object with a String (technically java allow you to do but .equals return always false). You probably want compare any line of string (received by Scanner throught .nextLine method). For do this, you have to compare the resulting strings. ex:
String line= scanner.nextLine();
if(line.equals("angry"))
.....
Beside this, like Ipang, me also dont understanded what have to do your code
+ 5
@Margaret I'm sorry for delay, I was fast asleep back then, unfortunately still didn't understand how the idea relate with the code, as the code doesn't seem to be doing something as you described, I'm not native English speaking either, so my English is just average : )
What @KrOW said was right, need to get a String from Scanner object nextLine() method, (let's call that "haystack") and check if it contains some specific word (let's call this "needle"), if the "needle" was found in "haystack", then we know what word to use to reply as output, based on what "needle" was found in "haystack". I hope you understand my idea : )
Thanks @KrOW, for a hand when I was not around : )
+ 4
@Margaret some examples please ... I still don't understand, @KrOW any ideas?
+ 4
Pretty margaret Dont worry... None was born learned ššš
+ 3
You comparing a Scanner object (YE) with a String...
+ 3
Pretty margaret Well, then you have to find a substring and not compare full line š
+ 2
Besid @Ipang suggestion, i suppose that "YE" object is not a String
+ 2
@Ipang ohhh i see , i just wanted to get a word and the see if the word is true then if the word is exactly the same as the one i gave it , do the other things ^^: ( sorry for my bad English , I'm actually new in this field(programming) so idk a lot about it ^^: ) and i wanted the output to String
+ 2
@Ipang for example : you put "i'm hungry" then you get the output "you should eat" and then a list comes ... or... for example you put "it's 9 Am" then the program says "u should go to the work "
+ 2
Ipang ???
+ 2
KrOW ohhh i see ! i'm learning java so i still don't know how to that ( basically i should study more ^^;) tnx againļ¼ć^ā^)ć
+ 2
Ipang Always ready for help if help is needed and if i can help š
+ 2
KrOW yup (ćļ¼¾āļ¼¾)
+ 2
Ipang ohhhh thank you į(āā½āį) and that's ok every human need sleepć( ^.^)ć
+ 1
@Ipang done! thanks for helping me :D
+ 1
@KrOW hmm...but i used string ... idk :(
+ 1
@KrOW i can't ? what should i do ?
+ 1
@Margaret maybe we can start with what output did you expect from the code, honestly I still don't understand what your intention with the code. For example, if input is x then expected output is y, something like that ...