Cannot invoke equals(char) on the primitive type char

后端 未结 2 1203
挽巷
挽巷 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:15

    Primitives are compared with ==. If you convert the chars to the wrapper classes Character, then you can use .equals().

    Either change

    1. char guess; to Character guess;

      or

    2. if(guess.equals(wordContainer[j])) to if(guess == wordContainer[j])).

提交回复
热议问题