• 10.13


    今天是在课上写了java四则运算的下一次升级:

    package suanshu;
    import java.util.*; 
    public class Suanshu {
        private static int [][]shu1=new int[100][100];//cun ru suo you de a de shu ju
        private static int [][]shu3=new int[100][100];//cun ru suo you de b de shu ju
        private static long []zhengquedaan=new long[100];//cun chu suo you zheng que da an
        private static int shu;//xuan ze jin xing ji ge shu de jia jian cheng chu
        private static int tiLiang;// xuan ze ti mu shu liang
        private static int chengChu;//pan duan shu fou you cheng chu fa
        private static int quZhiFanWei1;//qu zhi de qi shi zhi
        private static int quZhiFanWei2;//qu zhi de zhong zhi zhi
        private static long sum;//yong yu cun ru suan shi jie guo ,mei ci suan wuan zhi hou dou hui shua xin
        private static int[] cuoticishu=new int[100];//ji lu cuo ti shu
        private static long []cuotidaan=new long[100];//bao cuo tuo ti da an
        public static void yunsuanfu1(int c) {
            if(c==1) {
                System.out.print("+");
                
            }
            if(c==2) {
                System.out.print("-");
                
            }
            if(c==3) {
                System.out.print("*");
                
            }
            if(c==4) {
                System.out.print("/");
            }
        }
        public static void yunsuanfu2(int c) {
            if(c==1||c==2) {
                System.out.print("+");
                
            }
            if(c==3||c==4) {
                System.out.print("-");
                
            }
        }
        public static void Schutisanshu() {
            Scanner s = new Scanner(System.in);
            System.out.print("请选择题目数量:");
            tiLiang=s.nextInt();
            System.out.print("请选择是否有乘除法,是则输入1,否输入0");
            chengChu=s.nextInt();
            System.out.print("请选择取值范围:");
            quZhiFanWei1=s.nextInt();
            System.out.print("-");
            quZhiFanWei2=s.nextInt();
            System.out.print("请选择操作数个数:");
            shu=s.nextInt();
        }
        public static char zhuanhuan1(int a) {
            if(a==1) {
                return '+';
            }
            if(a==2) {return '-';}
            if(a==3) {return '*';}
            if(a==4) {return'/';}
            return 0;
        }
        public static char zhuanhuan2(int a) {
            if(a==1||a==2) {
                return '+';
            }
            if(a==3||a==4) {return '-';}
    
            return 0;
        }
        public static int Pchongfu(int i,int shu,int[] sh,int[] ch,int asd) {//pan duan ti mu shi fou chong fu
            int j,k;
            boolean panduan=true;
            if(i>=1) {
            for(j=0;j<i;j++) {
                for(k=0;k<shu;k++) {
                if(shu1[j][k]==sh[k]) {
                    if(k<shu-1) 
                    {if(shu3[j][k]==ch[k]) {
                    asd++;}}
                
                }
        
                if(asd==shu) {panduan=false;}}
            }}
            if(panduan==false) {//dang suan shi chong fu shi,jin xing xia ci xun huan,i-1
                return i-1;
            }
            return i;
        }
        public static void Ssuijishu(int[]sh,int[]ch) {
            int i,j,k;
        
            for(i=0;i<tiLiang;i++) {
                Random rand1 = new Random();
                Random x =new Random();//jue ding yun suan fu hao
                for(k=0;k<shu;k++) {
                 sh[k]=rand1.nextInt(quZhiFanWei2-quZhiFanWei1+1) + quZhiFanWei1;
                shu1[i][k]=sh[k];
                if(k<shu-1) {
                ch[k]=x.nextInt(4)+1;
                shu3[i][k]=ch[k];}
                }
        }}
        public static void suandaan1(int a,int b) {
            if(b==1) {
                sum=sum+a;
            }
            if(b==2) {
                sum=sum-a;
            }
            if(b==3) {
                sum=sum*a;
            }
            if(sum==4) {
                sum=sum/a;
            }
        }
        public static void suandaan2(int a,int b) {
            if(b==1||b==2) {
                sum=sum+a;
            }
            if(b==3||b==4) {
                sum=sum-a;
            }
    
        }
        public static void Zuoti(boolean panduan,int bb,int i) {
            int k,aa;
            Random randx=new Random();
            if(panduan==true&&chengChu==1) {
    
                    for(k=0;k<shu;k++) {
                        System.out.print(shu1[i][k]);
                    
                        aa=randx.nextInt(100)+1;
                        if(k==0) {
                            sum=shu1[i][k];
                        }
                        if(aa>30&&aa<60) {
                            if(bb==2) {
                                System.out.print(")");
                                bb++;
                            }
                        }
                        if(bb==2&&k==shu-1) {
                            System.out.print(")");
                        }
                        
                        if(k<shu-1) {
                            
                        yunsuanfu1(shu3[i][k]);
                        if(aa>30&&aa<60) {
                            if(bb==1) {
                                System.out.print("(");
                                bb++;
                            }
                        }
                        }if(k<shu-1) {
                        suandaan1(shu1[i][k+1],shu3[i][k]);}
                    }
                    System.out.print("=
    ");
                    zhengquedaan[i]=sum;
                    sum=0;
            }
            if(panduan==true&&chengChu==0) {
                for(k=0;k<shu;k++) {
                
                    aa=randx.nextInt(70)+1;
                    if(k==0) {
                        sum=shu1[i][k];
                    }
                    System.out.print(shu1[i][k]);
                    if(aa>30&&aa<60) {
                        if(bb==2) {
                            System.out.print(")");
                            bb++;
                        }
                    }
                    if(bb==2&&k==shu-1) {
                        System.out.print(")");
                    }
                    if(k<shu-1) {
                    
                    yunsuanfu2(shu3[i][k]);
                    if(aa>30&&aa<60) {
                        if(bb==1) {
                            System.out.print("(");
                            bb++;
                        }
                    }
                    }if(k<shu-1) {suandaan2(shu1[i][k+1],shu3[i][k]);}
    
                }
                zhengquedaan[i]=sum;
                System.out.print("=
    ");
                sum=0;
    
            }
        }
        public static void cuotiji(boolean panduan,boolean[] duicuo) {
            int k,i;
            for(i=0;i<tiLiang;i++) {
                if(duicuo[i]==false) {
            
            if(panduan==true&&chengChu==1) {
    
                    for(k=0;k<shu;k++) {
                        System.out.print(shu1[i][k]);
                        
                        if(k<shu-1) {
                        yunsuanfu1(shu3[i][k]);
                        }
                    }
                    System.out.print("=
    ");
            }
            if(panduan==true&&chengChu==0) {
                for(k=0;k<shu;k++) {
                    System.out.print(shu1[i][k]);
                    if(k<shu-1) {
                    yunsuanfu2(shu3[i][k]);
                    }
                    }
    
                }
    
                System.out.print("=
    ");}
            }
    
            }
        public  static void cuotichonglian(boolean panduan,boolean[] duicuo,int cuowushu) {
            int i;
            int daan;
            Scanner in = new Scanner(System.in);
            cuotiji(panduan,duicuo);
            System.out.println("请依次输入答案:");
            for(i=0;i<cuowushu;i++) {
                System.out.print("1.");
                daan=in.nextInt();
                if(daan!=cuotidaan[i]) {
                    System.out.println("错误,正确答案为:"+cuotidaan[i]);
                    cuoticishu[i]++;
                }
            }
            
        } 
        public static void main(String[] args) {
            int i,j=0;
            int choose1;
            double zhengqueshu=0,cuowushu=0;
            double zhengquelv;
            double yonghudaan;
            int bb;//aa yong yu panduan shi fou jia kuo hao
            Scanner s = new Scanner(System.in);
            int[] sh=new int[100];//yong yu jie shou sui ji shu
            int[] ch=new int[100];
            boolean[] duicuo=new boolean[100];
            Schutisanshu();
            int asd=0;//yi ge yong yu pan duan panduan shi fou wei true huo false de bianlinag
            boolean panduan=true;//pan duan shi fou chong fu
            Ssuijishu(sh,ch);
            for(i=0;i<100;i++) {
                cuoticishu[i]=1;
            }
            for(i=0;i<tiLiang;i++) {
                System.out.print((i+1)+".");
                bb=1;
                
                if(i==Pchongfu(i,shu,sh,ch,asd)) {panduan=true;}
                if(i!=Pchongfu(i,shu,sh,ch,asd)) {panduan=false;}
                i=Pchongfu(i,shu,sh,ch,asd);
                Zuoti(panduan, bb, i);
                yonghudaan=s.nextDouble();
                if(yonghudaan==zhengquedaan[i]) {
                    duicuo[i]=true;
                }
                else {duicuo[i]=false;
                cuotidaan[j]=zhengquedaan[i];
                j++;
                }
    }
            for(i=0;i<tiLiang;i++) {
                if(duicuo[i]==true) {zhengqueshu++;}
                else cuowushu++;
                System.out.print((i+1)+".");
                System.out.print(duicuo[i]);
            }
            zhengquelv=(zhengqueshu/(zhengqueshu+cuowushu))*100;
            System.out.print("
    正确率:");
            System.out.println(zhengquelv+"%");
            cuotiji(panduan,duicuo);
            System.out.print("请选择是否进行错题重做,是输入1,否输入2");
            choose1=s.nextInt();
            while(choose1==1) {
                cuotichonglian(panduan,duicuo,(int)cuowushu);
                for(i=0;i<(int)cuowushu;i++) {
                    System.out.print("第"+(i+1)+"道错题错误次数为"+cuoticishu[i]);
                    System.out.print("
    ");
                }
                System.out.print("请选择是否继续,是输入1,否输入2:");
                choose1=s.nextInt();
            }
            System.out.print("
    程序结束");
    }}
  • 相关阅读:
    js&jquery避免报错的方法
    if-else用法
    js-form表单元素的自定义属性
    a标签
    jQuery知识集锦
    JDK动态代理
    hibernate之多对一单向关联
    STL算法设计理念
    计算机常识--win7 删除文件、拒绝訪问等等,所有提示权限不够 解决的方法
    大话设计模式C++实现-第8章-工厂方法模式
  • 原文地址:https://www.cnblogs.com/zhaoyids/p/14135841.html
Copyright © 2020-2023  润新知