0

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
                }
}
DeveloperDemetri
  • 208
  • 2
  • 10
Jellyman
  • 11
  • 1
  • How is `input` and `Guess` defined? Please post a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) – radoh Mar 04 '16 at 23:32
  • The issue is that you are trying are using the '==' operator with 2 different types. 'letter' is a char, while 'cons' is an array of char. – DeveloperDemetri Mar 04 '16 at 23:34
  • Make `cons` a `String`, then use `indexOf()` to test if it contains the character: `String cons = "BCDFGHJ..."; if (cons.indexOf(letter) >= 0) { ... ` – erickson Mar 04 '16 at 23:56

1 Answers1

1

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?

Community
  • 1
  • 1
kunruh
  • 874
  • 1
  • 8
  • 17