我正在尝试使用数组来处理桥牌,然后按花色对其进行排序。该程序处理所有 13 张卡,但随后出现错误,
"Exception in thread "main"
java.lang.ArrayIndexOutOfBoundsException: 13
at DeckStuff.main(DeckStuff.java:29)"
任何帮助,将不胜感激。
public static void main(String[] args) {
Card.shuffleDeck();
Card.dumpCards();
Card[] bridgeHand = new Card[13];
for (int i = 0; i < bridgeHand.length; i++) {
bridgeHand[i] = Card.dealCard();
}
for (int i = 0; i < bridgeHand.length; i++) {
System.out.print(bridgeHand[i]);
}
System.out.println();
Card.sortHand(bridgeHand);
String[] suit = {"Spades", "Hearts", "Diamonds", "Clubs"};
int j = 0;
for(int i = 0; i < 4; i++) {
String s = suit[i].substring(0,1);
System.out.print("\n" + s + ": ");
while (bridgeHand[j].getCardSuitName().equals(suit[i])) {
System.out.print(bridgeHand[j]);
j++;
}
}
}
}