首页 > 代码库 > 随机出现300道四则运算数学题

随机出现300道四则运算数学题

package math;

public class math {
public static void subject(Object obj) {
System.out.println(obj);
}

public static void main(String[] args) {
subject("数学课后练习题:");
int count = 0;
for (int i = 0; i < 300; i++) {
int d1 = (int) ((Math.random()) * 100);
int d2 = (int) ((Math.random()) * 100);
int k = (int) ((Math.random()) * 100);
int k2 = (int) ((Math.random()) * 100);
int k3 = (int) ((Math.random()) * 100);
int k4 = (int) ((Math.random()) * 100);
int x = 1;
if (0 <= k && k < 12)
x = 1;
else if (12 <= k && k < 24)
x = 2;
else if (24 <= k && k < 36)
x = 3;
else if (36 <= k && k < 48)
x = 4;
else if (48 <= k && k < 60)
x = 5;
else if (60 <= k && k < 72)
x = 6;
else if (72 <= k && k < 84)
x = 7;
else
x = 8;
switch (x) {
case 1:
subject(d1 + "+" + d2 + "=");
break;
case 2:
jiafa(d1, d2);
break;
case 3:
subject(d1 + "*" + d2 + "=");
break;
case 4:
chufa(d1, d2);
break;
case 5:
subject(zhenfenshu(k, k2) + "+" + zhenfenshu(k3, k4) + "=");
break;
case 6:
subject(zhenfenshu(k, k2) + "-" + zhenfenshu(k3, k4) + "=");
break;
case 7:
subject(zhenfenshu(k, k2) + "*" + zhenfenshu(k3, k4) + "=");
break;
case 8:
subject(zhenfenshu(k, k2) + "/" + zhenfenshu(k3, k4) + "=");
break;
default:
subject("stop,stop,stop");
break;
}
count++;
}
subject("以上共有" + count + "四则运算练习题!");
}

public static void jiafa(int a, int b) {
if (a > b)
subject(a + "-" + b + "=");
else {
subject(b + "-" + a + "=");
}
}

public static void chufa(int a, int b) {
if (b > 0)
subject(a + "/" + b + "=");
else {
b = b + 10;
subject(a + "/" + b + "=");
}
}

public static String zhenfenshu(int a, int b) {
if (a <= b)
return a + "/" + b;
else
return b + "/" + a;
}
}

技术分享

技术分享

随机出现300道四则运算数学题