mardi 30 mars 2021

Random, Array and char in java

I need to take a random element from an array of chars

  1. C for hearts
  2. Q for diamonds
  3. F for clubs
  4. 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 int to char
  • The method next(int) from the type Random is not visible

The errors are both at casuale.next(arraySuits.length) but I don't know how to fix it.




Aucun commentaire:

Enregistrer un commentaire