[英]']' expected when writing Blackjack method
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();
}
Here is the segment of my code with the problem. 这是我的问题代码段。 I'm getting a problem where it says that it is expecting a ']', and I've tried to fix it to no avail.
我遇到了一个问题,它说它期望一个']',并且我试图将其修复为无济于事。 Any suggestions?
有什么建议么?
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"))
}
Also here is the specific error: 这也是特定的错误:
Error: ']' expected 错误:预期为']'
The problem is that you're trying to declare an array size in the array definition. 问题是您试图在数组定义中声明数组大小。 The array size should be initialized on the right side of the equal sign.
数组大小应在等号的右侧初始化。 Based on my knowledge of blackjack, I can provide these suggestions:
根据我对二十一点的了解,我可以提供以下建议:
You can continue to use an array, but you should still declare and initialize it outside of the while loop. 您可以继续使用数组,但仍应在while循环之外声明并初始化它。 If you use an array, be sure to set a size that is large enough to handle multiple hits.
如果您使用数组,请确保将大小设置为足以处理多个匹配。 You should use the following format if you continue to use an array:
如果继续使用数组,则应使用以下格式:
Card[] temp = new Card[x]
try this. 尝试这个。 your loop is meaning less.
您的循环意义不大。
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"));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.