I need to access the two String variables suit and rank,
then use them outside of the for loop. Is this at all possible?
public class Deck {
public static void main(String[] args) {
int deck[] = new int[52];
String suits[] = {"Spades", "Hearts", "Diamonds", "Clubs"};
String ranks[] = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
for(int i = 0; i < deck.length; i++) deck[i] = i;
for(int i = 0; i < deck.length; i++) {
int index = (int)(Math.random() * deck.length);
int temp = deck[i];
deck[i] = deck[index];
deck[index] = temp;
}
// randomizes the deck
for(int i = 1; i < deck.length; i++) {
String suit = suits[deck[i] / 13]; // I want to access these two Strings
String rank = ranks[deck[i] % 13]; // here
System.out.println(rank + "\t" + suit);
}
// and use them here
// I'm trying to make a poker game but need to use those two to deal a hand
}
}
suitorrankwill hold only last value.