我有一个项目,我在其中创建了一个x + y = z
or -
,*
运算符生成的函数,但我不明白如何创建另一个类,它将生成不同的答案并且用户必须找到正确的答案。
例子:2*2 = z
A2
B) 5
三)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;
}
}
然而,我不要求已经制定的代码,而是指示。
谢谢你。