• 小学一二年级出题器(JAVA加减乘除)


    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");
        }
    }
    
  • 相关阅读:
    我的创作纪念日(小小Unicorn)
    HTML篇一
    iOS 应用界面灰色主题
    OceanBase 如何通过日志观测冻结转储流程?
    十七、模型构建器(ModelBuilder)快速提取城市建成区——批量将夜光数据投影、转为整型(基于参考比较法)
    删除最近7天没有访问的文件
    python学习笔记12:小数类型的角度到度分秒的转换
    TCP的重传机制
    VMware12下安装Windows7虚拟机---详细多图教程(沙盒环境)
    暑期JAVA学习(44)注解
  • 原文地址:https://blog.csdn.net/jgszhuzhu/article/details/125456978