小学二年级0-100连加连减题目,类似47+36+11= ,52+13-19= ,49-19+27= ,45+24+17= ,49+21-28= ,61-21+16=
代码:
public class practice05 {
public static void main(String[] args) {
Random rand = new Random(); //生成随机数
int i = 0; //控制循环次数
while (i < 10) {
//rand.nextInt(MAX - MIN + 1) + MIN;
int num1 = rand.nextInt(91) + 10; //10~100之间的随机数
int num2 = rand.nextInt(91) + 10;
int num3 = rand.nextInt(91) + 10;
int result1 = num1 + num2 + num3; // a + b + c < 100
int result2 = num1 - num2 - num3; // a - b - c > 0
int result3 = num1 - num2; // a - b > 0
int result4 = num1 + num2; // a + b < 100
int result5 = result3 + num3; // a - b + c < 100
int result6 = result4 - num3; // a + b - c > 0
String blank = " "; //空格
//保证结果的合法性, a + b + c < 100,a - b - c > 0,a - b + c < 100,a + b - c > 0
if (result1 > 100 || result2 < 0 || result3 < 0
|| result4 > 100 || result5 > 100 || result6 < 0)
continue;
//交叉打印算式
if (i % 3 == 0) {
System.out.println(num1 + "+" + num2 + "+" + num3 + "=" + blank);
} else if (i % 3 == 1) {
System.out.println(num1 + "+" + num2 + "-" + num3 + "=" + blank);
} else if (i % 3 == 2) {
System.out.println(num1 + "-" + num2 + "+" + num3 + "=" + blank);
} else {
System.out.println(num1 + "-" + num2 + "-" + num3 + "=" + blank);
}
i++;
}
}
}
打印结果如下:
40+15-23=
46-16+10=
54+21+15=
55+17-16=
56-14+14=
50+10+12=