小学二年级乘法口诀练习题2,类似4× =28, ×6=12, ×2=4,6× =48,6× =42
代码:
public class practice03 {
public static void main(String[] args) {
Random rand = new Random(); //生成随机数
int i = 0; //控制循环次数
while (i < 100) {
//rand.nextInt(MAX - MIN + 1) + MIN;
int num1 = rand.nextInt(7) + 2; //生成2~9的随机数
String blank = " "; //空格
int result = rand.nextInt(79) + 2; //两数相乘的结果在2~81
int remainder = result % num1; //余数
int quotient = result / num1; //商
//商不能等于0和1(不等于1是想着提高难度),余数要等于0
if (remainder != 0 || quotient >= 10 || quotient == 1)
continue;
//交叉生成两张题目
if (i % 2 == 1 && num1 >= quotient) {
System.out.println(blank + "×" + num1 + "=" + result);
} else if (i % 2 == 0 && num1 >= quotient) {
System.out.println(quotient + "×" + blank + "=" + result);
}
i++;
}
}
}
打印结果如下:
6× =42
×3=9
×7=14
×5=25
2× =4
×6=36
4× =32
×7=35
×6=18