Java无法在Do循环中找到符号错误

时间:2014-12-17 16:38:24

标签: java

在此代码的最后一行我得到错误,它无法找到符号钱包。任何帮助将不胜感激。

int money = money();
boolean again = again("Ready");
do {
    int bet = bet(money);
    int wallet = wallet(bet);
    Deck deck = dealDeck();
    int com = comDeal(deck);
    int user = userDeal(deck);
    int userTotal = userHit(user, deck);
    int comTotal = comHit(com, deck, userTotal);
    int winner = whoWon(userTotal, comTotal);
    again = again("Play again");
}
while (again && wallet > 0);

1 个答案:

答案 0 :(得分:8)

int walletdo-while循环中定义。在while的条件下使用它是不允许的,因为它超出了范围。

只需在do-while循环之前声明此变量:

int money = money();
int wallet = 0;
boolean again = again("Ready");
do {
    //rest of code here...
} while (<condition>);