所以这是我的问题:我正在创建一个 String[] 变量来调用 main 方法以进行检查。每次我调用该变量时,它都会创建一个新牌组。我已经在方法和变量上尝试了 final 。这是我的 Dealer 类,它有我的 shuffle 方法。谢谢你的帮助。
package blackjack;
import java.util.*;
public class Dealer {
private Deck deck = new Deck();
private String[] deckArr = deck.deckArr;
private List list = new ArrayList<>(Arrays.asList(deckArr));
public String[] shuffDeck = shuffleDeck(deckArr);
private int count = 0 ;
public final String[] shuffleDeck(String[] deck) {
Collections.shuffle(list);
List<String> shufList = list;
deck = shufList.toArray(new String[shufList.size()]);
return deck;
}
public String deal() {
String dealtCard = null;
if (count < 52) {
dealtCard = shuffDeck[count];
}
else {
shuffleDeck(deckArr);
this.count = 0;
}
this.count++;
return dealtCard;
}
}
我的主要方法:主要用于测试目的。
package blackjack;
public class BlackJack {
public static void main(String[] args) {
Deck deck = new Deck();
Dealer dealer = new Dealer();
String str = dealer.deal();
for(int i = 0; i <52; i++)
System.out.println(dealer.shuffDeck[i]);
System.out.println();
System.out.println();
System.out.println(str);
}
}