public class AddSubMultiDivision { static int answerIndex = 0; public static void main(String[] args) { answerIndex = 0; StringBuffer stringBuffer = new StringBuffer(); StringBuffer stringBuffer1 = new StringBuffer(); stringBuffer.append("\r\n\n" + "Leve1" + "\r\n\n"); stringBuffer1.append("\r\n\n" + "Leve1" + "\r\n\n"); addAndSub(10, 20, stringBuffer, stringBuffer1); stringBuffer.append("\r\n\n" + "Leve2" + "\r\n\n"); stringBuffer1.append("\r\n\n" + "Leve2" + "\r\n\n"); addAndSub(20, 50, stringBuffer, stringBuffer1); stringBuffer.append("\r\n\n" + "Leve3" + "\r\n\n"); stringBuffer1.append("\r\n\n" + "Leve3" + "\r\n\n"); addAndSub(100, 50, stringBuffer, stringBuffer1); stringBuffer.append("\r\n\n" + "Leve4" + "\r\n\n"); stringBuffer1.append("\r\n\n" + "Leve4" + "\r\n\n"); addAndSub(1000, 50, stringBuffer, stringBuffer1); stringBuffer.append("\r\n\n" + "Leve5" + "\r\n\n"); stringBuffer1.append("\r\n\n" + "Leve5" + "\r\n\n"); multiAndDivision(50, 10, stringBuffer, stringBuffer1); System.out.println(stringBuffer.toString()); System.out.println(stringBuffer1.toString()); } /** * 加减法 * * @param max * @param count * @param stringBuffer * @param stringBuffer1 */ private static void addAndSub(int max, int count, StringBuffer stringBuffer, StringBuffer stringBuffer1) { for (int i = 0; i < count; i++) { for (int j = 0; j < 4; j++) { if (j % 2 == 0) { int number = (int) (Math.random() * max + 1); int number1 = (int) (Math.random() * max + 1); if (number > number1) { String str = number + " - " + number1 + " = "; stringBuffer.append(str); answerIndex++; stringBuffer1.append(answerIndex + "、" + (number - number1)); } else { String str = number1 + " - " + number + " = "; stringBuffer.append(str); answerIndex++; stringBuffer1.append(answerIndex + "、" + (number1 - number)); } stringBuffer.append(" "); stringBuffer1.append(" "); } else { int number = (int) (Math.random() * max + 1); int number1 = (int) (Math.random() * max + 1); String str = number + " + " + number1 + " = "; stringBuffer.append(str); answerIndex++; stringBuffer1.append(answerIndex + "、 " + (number1 + number)); stringBuffer.append(" "); stringBuffer1.append(" "); } } stringBuffer.append("\r\n"); // stringBuffer1.append("\r\n"); } stringBuffer1.append("\r\n"); } /** * 乘除法 * * @param max * @param count * @param stringBuffer * @param stringBuffer1 */ private static void multiAndDivision(int max, int count, StringBuffer stringBuffer, StringBuffer stringBuffer1) { for (int i = 0; i < count; i++) { for (int j = 0; j < 4; j++) { int number = (int) (Math.random() * max + 1); int number1 = (int) (Math.random() * max + 1); if (j % 2 == 0) { if (number > number1 && number % number1 == 0) { String str = number + " / " + number1 + " = "; stringBuffer.append(str); answerIndex++; stringBuffer1.append(answerIndex + "、" + (number / number1)); } else { boolean flage = false; for (int k = 0; k < 50000; k++) { number = (int) (Math.random() * max + 1); number1 = (int) (Math.random() * max + 1); if ((number > number1) && (number % number1 == 0)) { flage = true; break; } } if (flage) { String str = number + " / " + number1 + " = "; stringBuffer.append(str); answerIndex++; stringBuffer1.append(answerIndex + "、" + (number / number1)); } } } else { String str = number + " X " + number1 + " = "; stringBuffer.append(str); answerIndex++; stringBuffer1.append(answerIndex + "、" + (number * number1)); } stringBuffer.append(" "); stringBuffer1.append(" "); } stringBuffer.append("\r\n"); } stringBuffer1.append("\r\n"); } }