简单的java乘法游戏

时间:2018-04-22 12:45:50

标签: java

我正在制作一个简单的乘法游戏,但当用户输入正确的答案时,它仍会运行var data1 = dataTimePicker1.Value; cmd.Parameters.Add("@data1", MySqlDbType.Date).Value = data1; 语句。我知道这是一个简单的解决方案,但我无法弄明白。有人可以帮我一把吗?

else

3 个答案:

答案 0 :(得分:1)

你的别人错了,如果

public static void partB() {
    System.out.println("Exercise 1B");
    int count = 0;
    String active = "true";
    int correct = 0;
    while (active == "true") {
        Random r = new Random();
        int Low = 10; //inclusive
        int High = 21; //not inclusive
        int Result = r.nextInt(High - Low) + Low;
        Random r2 = new Random();
        int Result2 = r2.nextInt(High - Low) + Low;
        int Total = Result * Result2;
        Scanner input = new Scanner(System.in);
        System.out.println(Result + "*" + Result2 + "=?");
        String guess = new String(input.nextLine());
        String tostrng = String.valueOf(Total);

        if (guess.equals (tostrng)) {
            correct += 1;
            count+=1;
            System.out.println("Correct answer. Score: " + correct + "(" + count + ")");
        }
       else {
            count +=1;
            System.out.println("Incorrect answer. Score:" + correct + "(" + count + ")");
        }
        if (guess.equals("q")) {
            System.out.println("Good Bye!");
            active = "false";
            //return;
        }
    }
}

答案 1 :(得分:0)

将活动变量的类型设为boolean,即boolean active = true; 并且为了比较字符串值,请始终使用.equals()方法。

答案 2 :(得分:0)

修正了这样! 感谢你们的帮助。

if (guess.equals("q")) {
    System.out.println("Good Bye!");

    return;
}

if (guess.equals(tostrng)) {
    correct += 1;
    count += 1;

    System.out.println("Correct answer. Score: " + correct + "(" + count + ")");
} else {
    count += 1;

    System.out.println("Incorrect answer. Score:" + correct + "(" + count + ")");
}
相关问题