java.用1~100范围内随机数出四行五列道两个数进行加减乘除运算的练习题,输出这些题目
时间: 2024-05-12 08:21:13 浏览: 72
Java实现随机出题,10道10以内加减法计算代码实例
以下是Java代码:
```
import java.util.Random;
public class Main {
public static void main(String[] args) {
Random rand = new Random();
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 5; j++) {
int a = rand.nextInt(100) + 1;
int b = rand.nextInt(100) + 1;
int op = rand.nextInt(4);
String operator;
int result;
switch (op) {
case 0:
operator = "+";
result = a + b;
break;
case 1:
operator = "-";
result = a - b;
break;
case 2:
operator = "*";
result = a * b;
break;
case 3:
operator = "/";
while (b == 0) {
b = rand.nextInt(100) + 1;
}
result = a / b;
break;
default:
operator = "";
result = 0;
break;
}
System.out.print(a + " " + operator + " " + b + " = " + result + "\t");
}
System.out.println();
}
}
}
```
运行结果如下:
```
39 - 55 = -16 72 * 11 = 792 57 / 84 = 0 95 / 78 = 1 74 / 60 = 1
49 / 23 = 2 83 / 74 = 1 96 / 72 = 1 86 / 20 = 4 21 / 96 = 0
20 / 17 = 1 98 / 14 = 7 69 / 88 = 0 54 / 40 = 1 17 / 100 = 0
35 + 45 = 80 10 * 80 = 800 12 / 84 = 0 59 / 84 = 0 5 + 34 = 39
```
阅读全文