我目前正在从事Java游戏练习,但遇到了这个难以理解的错误。由于编译器将抛出其中的100个,因此一定是某种语法错误。但是我只是不知道错误在哪里?
import java.util.Random;
public class Poker
{
private Card[] deck;
private Card[] hand;
private int currentCard;
private int numbers[], triples, couples;
private String faces[], suits[];
private boolean flushOnHand, fourOfAKind, isStraight;
private static final int NUMBER_OF_CARDS = 52;
private static final Random randomNumbers = new Random();
Poker()
{
faces = { "Ace", "Deuce", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
suits = { "Hearts", "Diamonds", "Clubs", "Spades" };
numbers = new int[ 13 ];
deck = new Card[ NUMBER_OF_CARDS ];
triples = 0; // right here's where the compiler starts complaining
couples = 0;
...
虽然我无法发现任何语法错误?
顺便说一句,
Card
是一个单独的类。
最佳答案
没有理由不能在指示错误的位置分配变量triples
。
但是,您需要像这样分配String数组:
faces = new String[] { "Ace", "Deuce", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
suits = new String[] { "Hearts", "Diamonds", "Clubs", "Spades" };
关于java - 预期出现Java错误<identifier>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12342610/