')'期待,非法开始表达

时间:2012-12-04 03:24:11

标签: java

我遇到这样的错误:

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 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:1)

将行更改为

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

您只需传递已创建的对象名称即可。无需使用班级名称。

答案 2 :(得分:1)

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

blackjackplayer = checkForBlackJacks(playerhand);

不是这个

blackjackplayer = checkForBlackJacks(BlackJackHand playerhand);

如果您查看错误消息的字符位置,则很可能位于playerHand符号的位置...并且它告诉您它期望该符号为{{1} }。如果您不理解错误消息,通常会尝试从字面意义上阅读它...

答案 3 :(得分:0)

你不需要在那些行中说出BlackJackHand playerHand。只是玩家手就可以了。