9.24学习总结

(1)今日安排

四则运算第一阶段

(2)源代码

package size;
import java.util.*;
import java.lang.Math;
public class text {
     
    static Random random = new Random();
    static  int count=0;
    static String []arr = new String[1000];
    //生成随机符号
        public static char operator(int se) {
            char op=' ';       
           int  n = random.nextInt(100);
            if(se==1) 
            {
                switch(n%4)
                {
                case 0:op = '+';break;
                case 1:op = '-';break;
                case 2:op = '*';break;
                case 3:op = '/';break;
                }
            }
            if(se==2)
            {
                switch(n%2)
                {
                case 0:op = '+';break;
                case 1:op = '-';break;
                }
            }
            return op;
        }
        
        public static String problem(int min,int max,int sumoperate,int chengchu) {
            int a = (int)(Math.random()*(max-min)+min);
            int b = (int)(Math.random()*(max-min)+min);
            char c = operator(chengchu);
            String str = ""+a+c+b;
            
            for(int i=2;i<sumoperate;i++)
            {
               int zenjiashu = (int)(Math.random()*(max-min)+min);
                char zenjiac = operator(chengchu);
                str = str + zenjiac + zenjiashu;
            }
            return str;
        }
            
    //查重
        public static void chachong(int min,int max,int sumoperand,int chengchu)
        {
            arr[count]=problem(min,max,sumoperand,chengchu);
            if(count==0)
            {
                count++;
                System.out.println(arr[0]+"=");
            }
            else
            {
                boolean flag = true;
                for (int j = 0; j <count; j++) 
                {
                            if( arr[count]== arr[j]) flag = false;
                }
                if(flag)
                {
                    System.out.println(arr[count]+"=");
                    count++;
                }
                else
                {
                    chachong(min,max,sumoperand,chengchu);
                }
            }
        }
        
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int sumtitle;//出题个数
            int sumoperand;//操作数个数
            int min,max;
            int chengchu;
            System.out.println("请输入出题个数:");
            sumtitle = sc.nextInt();
            System.out.println("请输入操作数个数:");
            sumoperand = sc.nextInt();
            System.out.println("请输入操作数范围:");
            min = sc.nextInt();
            max = sc.nextInt();
            System.out.println("是否需要乘除运算:1.需要 2.不需要");
            chengchu = sc.nextInt();
            for(int i=0;i<sumtitle;i++)
            {
                chachong(min,max,sumoperand,chengchu);
            }
        }
}

 

posted @ 2021-09-24 20:07  今天又双叒叕在敲代码  阅读(18)  评论(0编辑  收藏  举报