Reputation: 11
I'm working on a mini wheel of fortune game, and I'm trying to restrict the use of a vowel, since they did not buy it.
What I'm not understanding is the if loop at the end. it says that it is incompatible with the operand types, but I'm not sure why. Am I doing something wrong?
char[] cons= {'B','C','D','F','G','H','J','K','L','M','N','P','Q','R','S','T','V','W','X','Y','Z'};
switch (input) {
case Guess:
System.out.println("The wheel lands on $" + spins);
System.out.println("Guess a consonant");
char letter = kb.next().toUpperCase().charAt(0);
if (letter == cons[]) {
//allow usage of letter
}
}
Upvotes: 0
Views: 1034
Reputation: 874
If I understand correctly, you are trying to make sure the letter is contained inside the cons
array. You can't use the ==
operator like that because you are trying to compare a char
with a char[]
. You'll want to do some sort of contains
check.
This answer has some pretty good options: In Java, how can I determine if a char array contains a particular character?
Upvotes: 1