用java语言写一个生成100以内加减法算式+
时间: 2024-05-05 21:20:13 浏览: 90
以下是使用Java语言生成100以内加减法算式的示例代码:
```java
import java.util.Random;
public class ArithmeticGenerator {
public static void main(String[] args) {
Random random = new Random();
int num1, num2, result;
char operator;
for (int i = 0; i < 10; i++) {
num1 = random.nextInt(100);
num2 = random.nextInt(100);
operator = random.nextBoolean() ? '+' : '-';
result = operator == '+' ? num1 + num2 : num1 - num2;
System.out.println(num1 + " " + operator + " " + num2 + " = " + result);
}
}
}
```
运行结果示例:
```
40 - 27 = 13
63 - 43 = 20
85 - 38 = 47
49 + 11 = 60
17 + 62 = 79
86 - 45 = 41
51 - 35 = 16
61 - 34 = 27
9 + 87 = 96
31 - 7 = 24
```
阅读全文