要口算题,那就写个吧。。。

来源:互联网 发布:微信多开软件安全吗 编辑:程序博客网 时间:2024/04/28 19:18

要口算题,那就写个吧。。。

 

/** * 生成20以内的加减口算题 */private static void generateMental() {Random ra = new Random();int count = 0;while (count < 100) {int firstSymbol = ra.nextInt(2) % 2;String fs = "";int secondSymbol = ra.nextInt(2) % 2;String ss = "";int first = ra.nextInt(20);int second = ra.nextInt(20);int third = ra.nextInt(20);if (first == 0 || second == 0 || third == 0) {continue;}int result = 0;if (firstSymbol == 1) {fs = " + ";result = first + second;if (result > 20) {continue;}} else {fs = " - ";result = first - second;if (result < 0) {continue;}}if (secondSymbol == 1) {ss = " + ";result = result + third;} else {ss = " - ";result = result - third;}if (result > 0 && result < 20 ) {System.out.println(first + fs + second + ss + third + " = ");count ++;}if (count % 25 == 0) {System.out.println("========" + count / 25 + "=========");}}}