今天又是周一啦,新的一周开始啦
为了明天的JAVA课,我优化了一下二柱子的代码,如果能正好应和到老师的要求那就万万岁了
这是优化之后的效果:
public class Totenfour { @SuppressWarnings("resource") public static void main(String[] args) { Random rand = new Random(); int numT,numU=0,max=10,min=99; int choice=0; int[] cp=new int[100]; int[] cd=new int[100]; int[] keka=new int[100]; boolean[] pp=new boolean[100]; int answer=0; int pop=0,poe=0; int[] happy=new int[100]; int[] opea=new int[100]; Scanner in=new Scanner(System.in); System.out.print("请输入题目数"); numT=in.nextInt(); System.out.print("请输入最大值"); max=in.nextInt(); System.out.print("请输入最小值"); min=in.nextInt(); randomSet(cp,cd,numT,numU,max,min); for(int i=0;i<numT;i++) { System.out.print("第"+(i+1)+"题 "); choice=rand.nextInt(4); switch(choice) { case 0: opea[i]=0; keka[i]=cp[i]+cd[i]; System.out.print(cp[i]+"+"+cd[i]+"="); answer=in.nextInt(); if(answer==keka[i]){pp[i]=true;} else {pp[i]=false;happy[poe]=i;poe++;} break; case 1: opea[i]=1; keka[i]=cp[i]-cd[i]; System.out.print(cp[i]+"-"+cd[i]+"="); answer=in.nextInt(); if(answer==keka[i]){pp[i]=true;} else {pp[i]=false;happy[poe]=i;poe++;} break; case 2: opea[i]=2; keka[i]=cp[i]*cd[i]; System.out.print(cp[i]+"x"+cd[i]+"="); answer=in.nextInt(); if(answer==keka[i]){pp[i]=true;} else {pp[i]=false;happy[poe]=i;poe++;} break; case 3: opea[i]=3; keka[i]=cp[i][i]; System.out.print(cp[i]+"/"+cd[i]+"="); answer=in.nextInt(); if(answer==keka[i]){pp[i]=true;} else {pp[i]=false;happy[poe]=i;poe++;} break; } } pop=curry(pp,numT); for(;pop!=1;) { int k=poe; System.out.println("这里还有错题哦,一共"+poe+"道题目"); for(int i=0;i<k;i++) { switch(opea[happy[i]]) { case 0: System.out.print("第"+(happy[i]+1)+"题 "); keka[happy[i]]=cp[happy[i]]+cd[happy[i]]; System.out.print(cp[happy[i]]+"+"+cd[happy[i]]+"="); answer=in.nextInt(); if(answer==keka[happy[i]]){pp[happy[i]]=true;poe--;} break; case 1: System.out.print("第"+(happy[i]+1)+"题 "); keka[happy[i]]=cp[happy[i]]-cd[happy[i]]; System.out.print(cp[happy[i]]+"-"+cd[happy[i]]+"="); answer=in.nextInt(); if(answer==keka[happy[i]]){pp[happy[i]]=true;poe--;} break; case 2: System.out.print("第"+(happy[i]+1)+"题 "); keka[happy[i]]=cp[happy[i]]*cd[happy[i]]; System.out.print(cp[happy[i]]+"x"+cd[happy[i]]+"="); answer=in.nextInt(); if(answer==keka[happy[i]]){pp[happy[i]]=true;poe--;} break; case 3: System.out.print("第"+(happy[i]+1)+"题 "); keka[happy[i]]=cp[happy[i]][happy[i]]; System.out.print(cp[happy[i]]+"/"+cd[happy[i]]+"="); answer=in.nextInt(); if(answer==keka[happy[i]]){pp[happy[i]]=true;poe--;} break; } } pop=curry(pp,numT); } System.out.println("恭喜,全部正确啦"); in.close(); } public static int curry(boolean[] i,int numT) { for(int c=0;c<numT;c++) { if(i[c]==false) { return 0; } } return 1; } public static int check(int[] kp,int [] kk,int i,int s) { for(int k=0;k<=50;k++) { if((kk[k]==i)&&(kp[k]==s)) {return 0;} } return 1; } public static void randomSet(int a[],int b[],int numT,int numU ,int max,int min) { Random rand = new Random(); int r;int p; for(int x=0;x<numT;x++) { r=rand.nextInt(max-min+1) + min; p=rand.nextInt(max-min+1) + min; int op=check(a,b,r,p); for(;op!=1;) { r=rand.nextInt(max-min+1) + min; p=rand.nextInt(max-min+1) + min; op=check(a,b,r,p); } a[x]=r;b[x]=p; } } }
这样就能确定错题数目啦,不过算式生成查重还是没太搞明白,明天做的时候再看看效果吧
好,今天就是这样啦