数学创建 x + y = z 函数生成答案

Math created x + y = z function generate answers

我有一个项目,我在其中创建了一个 x + y = z-* 操作员生成的函数,但我不明白如何创建另一个 class它将生成不同的答案,用户必须找到正确的答案。

示例2*2 = z

A) 2

B) 5

C) 6

D) 4

这是我已经完成的代码:

public class Equation {
    int x,y,z;

        public Equation() {
        Random r = new Random();
         x = r.nextInt(50) + 1;
         y = r.nextInt(50) + 1;
         z = 0;
        char operator ='?';         

        switch (r.nextInt(3)){
        case 0: operator = '+';
                z = x+y;
                break;
        case 1: operator = '-';
                z = x-y;;
                break;
        case 2: operator = '*';
                z = x*y;;
                break;
        default: operator = '?';
      }

      System.out.print(x);
      System.out.print(" ");
      System.out.print(operator);
      System.out.print(" ");
      System.out.print(y);
      System.out.print(" = ");
      System.out.println(z);


    }
    public static void main(String[] args) {
        Equation eq= new Equation();
        String param = null;




    }

}

但我要的不是代码,而是指示。

谢谢。

你问,"how I can make another class where it will generate different answers and the user has to find the right one."一种方法是取正确的值z,生成不同的随机值,然后输出所有值,正确的和不正确的。

类似于:

incorrect = r.nextInt(2*z);

生成 0 到 2*z 范围内的值。您将需要确保不正确的值彼此不同,并且都与 z 不同。