I am trying to create mutliple methods which all use data from the same array. The method createDeck works fine. But for the other two methods, they just return null. Is there a way to fix this?
class Deck
{
private static String[] suit = {"Spades", "Diamonds", "Clubs", "Hearts"};
private static String[] rank = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen",
"King", "Ace"};
private static String[] deck = new String[52];
// create deck
static void createDeck()
{
for (int i = 0; i < deck.length; i++)
{
deck[i] = rank[i % 13] + " of " + suit[i / 13];
System.out.println(deck[i]);
}
}
// shuffle deck
static void shuffleDeck()
{
// shuffle the deck
for (int i = 0; i < deck.length; i++)
{
int index = (int) (Math.random() * deck.length);
String temp = deck[i];
deck[i] = deck[index];
deck[index] = temp;
}
// print the shuffled deck
for (String u : deck)
{
System.out.println(u);
}
}
static void findTop()
{
System.out.println(deck[0]);
}
}