So, I have this code and I'm trying to use an indexOf to find a specific card of the deck but every time I try I keep getting an error. Any ideas?
public class Cards {
public static void main(String[] args) {
int Shuffles = Integer.parseIn t(args[0]);
int Evaluation = Integer.parseIn t(args[1]);
String[] SUITS = {
"Clubs", "Diamonds", "Hearts", "Spades"
};
String[] RANKS = {
"2", "3", "4", "5", "6", "7", "8", "9", "10",
"Jack", "Queen", "King", "Ace"
};
int n = SUITS.length * RANKS.length;
if (Shuffles > 5)
throw new RuntimeExceptio n("Maximum of 5 shuffles");
// initialize deck
String[] deck = new String[n];
for (int i = 0; i < RANKS.length; i++) {
for (int j = 0; j < SUITS.length; j++) {
deck[SUITS.length*i + j] = RANKS[i] + " of " + SUITS[j];
}
}
String temp ="";
// shuffle
for (int i = 0; i < n; i++) {
int r = i + (int) (Math.random() * (n-i));
temp = deck[r];
deck[r] = deck[i];
deck[i] = temp;
}
// print shuffled deck
if (Shuffles == 1)
System.out.prin tln("Shuffling " + Shuffles + " time.");
else
System.out.prin tln("Shuffling " + Shuffles + " times.");
System.out.prin tln(deck[Evaluation]);
deck[Evaluation] = deck[Evaluation];
System.out.prin tln();
System.out.prin tln("Starting position: 0");
for (int q = 1; q <= Shuffles; q++) {
for (int i = 0; i < n; i++) {
int r = i + (int) (Math.random() * (n-i));
temp = deck[r];
deck[r] = deck[i];
deck[i] = temp;
}
System.out.prin tln("Shuffle " +q+ ":" + deck.indexOf(de ck[Evaluation]));
}
}
}
public class Cards {
public static void main(String[] args) {
int Shuffles = Integer.parseIn t(args[0]);
int Evaluation = Integer.parseIn t(args[1]);
String[] SUITS = {
"Clubs", "Diamonds", "Hearts", "Spades"
};
String[] RANKS = {
"2", "3", "4", "5", "6", "7", "8", "9", "10",
"Jack", "Queen", "King", "Ace"
};
int n = SUITS.length * RANKS.length;
if (Shuffles > 5)
throw new RuntimeExceptio n("Maximum of 5 shuffles");
// initialize deck
String[] deck = new String[n];
for (int i = 0; i < RANKS.length; i++) {
for (int j = 0; j < SUITS.length; j++) {
deck[SUITS.length*i + j] = RANKS[i] + " of " + SUITS[j];
}
}
String temp ="";
// shuffle
for (int i = 0; i < n; i++) {
int r = i + (int) (Math.random() * (n-i));
temp = deck[r];
deck[r] = deck[i];
deck[i] = temp;
}
// print shuffled deck
if (Shuffles == 1)
System.out.prin tln("Shuffling " + Shuffles + " time.");
else
System.out.prin tln("Shuffling " + Shuffles + " times.");
System.out.prin tln(deck[Evaluation]);
deck[Evaluation] = deck[Evaluation];
System.out.prin tln();
System.out.prin tln("Starting position: 0");
for (int q = 1; q <= Shuffles; q++) {
for (int i = 0; i < n; i++) {
int r = i + (int) (Math.random() * (n-i));
temp = deck[r];
deck[r] = deck[i];
deck[i] = temp;
}
System.out.prin tln("Shuffle " +q+ ":" + deck.indexOf(de ck[Evaluation]));
}
}
}
Comment