Cannot invoke equals(char) on the primitive type char

后端 未结 2 1198
挽巷
挽巷 2020-12-29 16:58

I\'m new to programming and trying to nut out a basic guessing game, but I have this error. Need some help as I\'ve set \'guess\' to char, then want to compare

2条回答
  •  不思量自难忘°
    2020-12-29 17:10

    equals() is a method that is contained in the Object class and passed on through inheritance to every class that is created in java. And since it is a method, it can be invoked only by objects and not primitives.

    You should compare the variable guess like this

    if(guess==wordContainer[j]) {
    

    hope it helps.

提交回复
热议问题