【发布时间】:2020-07-18 17:41:42
【问题描述】:
目前我正在尝试通过使用 for 循环来获取每张卡片,用一副卡片填充 ArrayList。它并没有像我预期的那样工作,希望有人能指出我正确的方向。
我看到以下错误:
System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
我的甲板课:
public class Deck{
private final int deckSize = 52;
private final String[] suit = {"hearts", "clubs", "diamonds", "spades"};
private final String[] face = {"Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"};
ArrayList<String> currentDeck = new ArrayList<String>(deckSize);
public void getDeck(){
for(int i=0; i<face.length; i++) {
for(int j=0; j<suit.length; j++){
String cards = face[i] + " of " + suit[j];
currentDeck.add(cards);
}
}
System.out.println(currentDeck);
}
}
主类;
public static void main(String[] args) {
printDeck();
}
public static void printDeck(){
Deck deck = new Deck();
deck.getDeck();
}
【问题讨论】:
-
你打算如何工作?
-
出现哪个错误?逻辑工作正常。在任何情况下,您都需要声明 main 方法。请发送您的文件的可复制示例
-
请提供预期的输出。逻辑似乎很好。
-
我已经实例化了甲板类,并且在主方法中正确调用了该方法作为
deck.getDeck。我收到错误Exception: System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension. -
我希望数组列表中包含一副纸牌中的所有纸牌。例如黑桃 A