I have a program that generates a deck of playing cards and displays seven random cards. I tried to pass the seven cards that were selected into a string, however I only know how to set the entire array to a string, not just the selected 7 cards.
public class PlayedCards{
public static void main(String[] args){
int[] deck = new int[52];
String[] suits = {"Spades", "Clubs", "Diamonds", "Hearts"};
String[] ranks = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
for (int a = 0; a < deck.length; a++){
deck[a]= a;
}
for (int a = 0; a <deck.length; a++){
int order = (int)(Math.random() * deck.length);
int temp = deck[a];
deck[a] = deck[order];
deck[order] = temp;
}
for (int a = 0; a < 7; a++){
String suit = suits[deck[a] / 13];
String rank = ranks[deck[a] % 13];
System.out.println(rank + " of " + suit);
}
System.out.println(rank + " of " + suit);
}
}
My questions are:
Are the cards that are displayed the values of 0-6 in my array?
If so, how would I set those values for the array to a separate string that i could then recall for the user as being played?