0

我收到这样的错误:

Test. java:8 :')' expected
Test. java: 8: error :illegal start of expression
Test. java:9 :')' expected
Test. java: 9: error :illegal start of expression

第 8 行和第 9 行是:

blackjackplayer = checkForBlackJacks(BlackJackHand playerhand);
blackjackdealer = checkForBlackJacks(BlackJackHand dealerhand);

课程是:

  public class Test{
        public void playround (){
                int temp = -1;
                playerhand = new BlackJackHand(22);
                dealerhand = new BlackJackHand(22);
                addCards(playerhand, 2);
                addCards(dealerhand, 2);
                blackjackplayer = checkForBlackJacks(BlackJackHand playerhand);
                blackjackdealer = checkForBlackJacks(BlackJackHand dealerhand);
                while(temp!=2&&playerhand.gettotal()<=21){
                    printHands(false, true, true);
                    temp = Prompt.getInt("\nPress 1 to hit, or 2 to stand. ", 1, 2);
                    if (temp==1&&playerhand.gettotal()<=21){
                        addCards(playerhand,1);
                    }
                }
                if (playerhand.gettotal()>21){
                    playerbust = true;
                }
                else{
                    seeWhoWon();
                }
                    //done = true;
        }
        public boolean checkForBlackJacks (BlackJackHand x){
            return (x.gettotal()==21&&x.getmyhand().size()==2);
        }
    }

这只是一个包含错误部分的 java 文件。真正的程序具有所有组件。

4

4 回答 4

3

将值作为方法参数传递时,您必须只包含对象的名称,而不是其类型。

blackjackplayer = checkForBlackJacks(playerhand);
blackjackdealer = checkForBlackJacks(dealerhand);
于 2012-12-04T03:26:09.433 回答
1

将行更改为

blackjackplayer = checkForBlackJacks(playerhand);
blackjackdealer = checkForBlackJacks(dealerhand);

您只需要传递已经创建的对象名称。无需使用类名。

于 2012-12-04T03:26:26.337 回答
1

这显然是一个语法错误。方法调用如下所示:

blackjackplayer = checkForBlackJacks(playerhand);

不是这个

blackjackplayer = checkForBlackJacks(BlackJackHand playerhand);

如果您查看错误消息的字符位置,它很可能在playerHand符号的位置 ... 并且它告诉您它期望 THAT 符号是')'. 如果您不理解错误消息,尝试从字面意义上阅读它通常会有所帮助...

于 2012-12-04T03:26:27.483 回答
0

你不需要在那些行中说 BlackJackHand playerHand。只需 playerHand 即可。

于 2012-12-04T03:26:15.873 回答