while (hitOrStay.equalsIgnoreCase("hit"))
{
Card temp[hitOrStayCounter] = cardDeck.deal(); // issue occurs on this line
System.out.println("You are delt a " + temp[hitOrStayCounter].getBJ());
hitOrStayCounter++;
System.out.println("Would you like to hit again?");
hitOrStay = ketboard.next();
}
以下是我的代码中有问题的部分。我遇到一个问题,它说它正在期待一个']',我试图修复它无济于事。有什么建议吗?
public Card deal()
{
nextCard++;
return deck[nextCard-1];
}
public static void main(String[] args)
{
int hitOrStayCounter=5;
Bankroll money = new Bankroll();
Deck cardDeck = new Deck();
Scanner keyboard = new Scanner(System.in);
System.out.println("Would you like to play?");
String playGame = keyboard.next();
while (playGame.equalsIgnoreCase("yes"))
}
此处还有具体错误:
错误:']'预期
答案 0 :(得分:0)
问题是你试图在数组定义中声明一个数组大小。阵列大小应该在等号的右侧初始化。根据我对二十一点的了解,我可以提供以下建议:
您可以继续使用数组,但仍应在while循环之外声明并初始化它。如果使用数组,请确保设置足够大的大小以处理多个匹配。如果继续使用数组,则应使用以下格式:
Card[] temp = new Card[x]
答案 1 :(得分:0)
试试这个。你的循环意义不大。
public static void main(String[] args)
{
do{
int hitOrStayCounter=5;
Bankroll money = new Bankroll();
Deck cardDeck = new Deck();
Scanner keyboard = new Scanner(System.in);
System.out.println("Would you like to play?");
String playGame = keyboard.next();
}while (playGame.equalsIgnoreCase("yes"));
}