-2

我正在制作二十一点游戏,但由于某种原因无法使 else 语句起作用。你能纠正这个并正确解释吗?

 {
    if (user.equalsIgnoreCase("next card"))
        b = ran.nextInt(1 + 9) + 1;
        y = x + c + b;
        System.out.println("You received " + b + " And together your cards equal " + y + " .");
    } else {
        System.out.println("You decided to stay.");
    }

http://prntscr.com/20rq6s

4

3 回答 3

7

正确使用括号,你的括号在“if”块之外:

if (/*condition*/) {
    // Do code
} else {
    // Do other code
}
于 2013-10-30T16:30:11.060 回答
0
if(user.equalsIgnoreCase("next card")) { 
    b = ran.nextInt(1 + 9)+1; 
    y = x + c + b; 
    System.out.println("You received " +b+ " And together your cards equal " +y+ " ."); 
} else { 
    System.out.println("You decided to stay."); 
}
于 2013-10-30T16:33:35.890 回答
0

IF您的陈述没有正确的结构。看看下面的文章......它将解释所需的结构。

http://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html

希望它能消除您可能遇到的任何困惑。

希望这可以帮助。

于 2013-10-30T17:08:17.313 回答