非法启动表达式错误,使用方法

时间:2014-03-20 19:50:32

标签: methods expression

因此,当我尝试运行使用方法练习的DiceGame程序时,我在第30行周围不断开始表达错误。这是我的代码:

import java.util.Scanner;
public class DiceGame
{
    public static void main(String[] args)
    {
        final int RANGE = 6; 
        Scanner input = new Scanner(System.in);
        int userGuess = input.next();
        int throwResult = throw2Dice(RANGE); 
        int programGuess = throw2Dice(RANGE);


        int userError = Math.abs(throwResult - userGuess);
        int programError = Math.abs(throwResult - programGuess); 
        boolean userWins = false; 
        if(userError < programError)
        {
            userWins = true; 
        {
        System.out.println("Your guess was: " + userGuess + " the program's guess was: " + programGuess + " and the result was: " + throwResult); 
        if(userWins == false)
            System.out.println("Program Wins!!!");
        else
            System.out.println("User Wins!!!"); 
    }


    public static int throw2Dice(int r)
    { 
        int number1 = (Math.random() * r + 1);
        int number2 = (Math.random() * r + 1);
        int sum = number1 + number2; 
        return sum; 
    }
}

1 个答案:

答案 0 :(得分:1)

if(userError < programError)
{
    userWins = true; 
{

你有两个开括号,而不是一个开括号和近括号。