I have to: Create an array that models a deck of cards. For example, “1_of_diamonds” represents the ace of diamonds, “2_of_diamonds” represents the 2 of diamonds, up to “13_of_diamonds”, which represents the King of diamonds. The suits clubs, hearts and spades are represented in a similar manner. All these elements should be in a single array. The array should be populated using a counter controlled loop. Output the contents of the array to the screen. Shuffle the deck.
I have the code to shuffle it working but I do not know how to populate the array with a counter controlled loop.
//this is my code
import java.util.Random;
public class Cards{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
} //end main
public String[] shuffle(String[] deck) {
Random rnd = new Random();
for (int i = deck.length - 1; i >= 0; i--)
{
int index = rnd.nextInt(i + 1);
// Simple swap
String a = deck[index];
deck[index] = deck[i];
deck[i] = a;
}
return deck;
}
}// end class
Aucun commentaire:
Enregistrer un commentaire