I need to take a random element from an array of chars
- C for hearts
- Q for diamonds
- F for clubs
- P for spades
Random casuale = new Random()
char[] arraySuits = {'c', 'c', 'c', 'q', 'q', 'q', 'f', 'f', 'f', 'p', 'p', 'p',};
location1S=casuale.next(arraySuits.length);
location2S=casuale.next(arraySuits.length);
There are two errors:
- Type mismatch: cannot convert from
inttochar - The method
next(int)from the typeRandomis not visible
The errors are both at casuale.next(arraySuits.length) but I don't know how to fix it.
Random::nextdoesn't do what you think it does. You probably wantcasuale.nextInt(vetSuits.length)