Help, I am to Use Math.random()and the remainder operator to generate 52 distinct numbers from 0 to 51. These numbers will represent a deck of card and let’s call it deckOfCard. (Now you have a one-dimensional array of size 52.) For this step, you should write a method called generateCardwhich returns nothing but accepts one argument which is the array variable that represents the deck of card(pass by value). For the output, I am trying to get UNIQUE random numbers.
public class Decks {
public static void main(String[] args) {
generate();
}
public static void generate() {
int deckOfCard[] = new int[52];
for (int counts = 0; counts < 52; counts++) {
deckOfCard[counts] = (int) (Math.random() * 51);
}
for (int count = 0; count < deckOfCard.length; count++) {
System.out.print("\t" + deckOfCard[count]);
}
}
}
Aucun commentaire:
Enregistrer un commentaire