package 测试; import java.util.*; public class Addition { public static void Repeat(int a[ ],int b[ ],int c[ ],int n) { Random rand=new Random( ); int i,j; for(i=0;i<n;i++) { for(j=0;j<i;j++) { while(a[j]==a[i]&&b[j]==b[i]&&c[j]==c[i]) { a[i]=rand.nextInt(100); break; } } } } public static void RandomInt(int a[ ],int b[ ],int c[ ],int n,int m,int d) { int i,temp; Random rand=new Random( ); for(i=0;i<n;i++) { a[i]=rand.nextInt(d-m)+(m); b[i]=rand.nextInt(d-m)+(m); c[i]=rand.nextInt(4); if(a[i]<b[i]) { temp=a[i]; a[i]=b[i]; b[i]=temp; } switch(c[i]) { case 0:System.out.print(i+1+" "+a[i]+"+"+b[i]+"="+'\n');break; case 1:System.out.print(i+1+" "+a[i]+"-"+b[i]+"="+'\n');break; case 2:System.out.print(i+1+" "+a[i]+"×"+b[i]+"="+'\n');break; case 3:System.out.print(i+1+" "+a[i]+"/"+b[i]+"="+'\n');break; } } } public static void Exem(int a[ ],int b[ ],int c[ ],int error[ ],int n) { int i,g,h=0,k=0; int []count2=new int[100]; int d[]=new int[100]; Scanner scan=new Scanner(System.in); System.out.print("欢迎来到答题系统!"+'\n'); for(i=0;i<n;i++) { switch(c[i]) { case 0: { System.out.print(i+1+" "+a[i]+"+"+b[i]+"="); g=scan.nextInt( ); if(g==a[i]+b[i]) { h++; System.out.print("回答正确!"+'\n'); } else { count2[i]++; System.out.print("回答错误!"+" "+count2[i]+'\n'); error[k]=i; k++; } }break; case 1: { System.out.print(i+1+" "+a[i]+"-"+b[i]+"="); g=scan.nextInt( ); if(g==a[i]-b[i]) { h++; System.out.print("回答正确!"+'\n'); } else { count2[i]++; System.out.print("回答错误!"+" "+count2[i]+'\n'); error[k]=i; k++; } }break; case 2: { System.out.print(i+1+" "+a[i]+"*"+b[i]+"="); g=scan.nextInt( ); if(g==a[i]*b[i]) { h++; System.out.print("回答正确!"+'\n'); } else { count2[i]++; System.out.print("回答错误!"+" "+count2[i]+'\n'); error[k]=i; k++; } }break; case 3: { System.out.print(i+1+" "+a[i]+"/"+b[i]+"="); g=scan.nextInt( ); if(g==a[i]/b[i]) { h++; System.out.print("回答正确!"+'\n'); } else { count2[i]++; System.out.print("回答错误!"+" "+count2[i]+'\n'); error[k]=i; k++; } }break; } } System.out.print("正确率:"+(double)h/n+'\n'); if((double)h/n!=1) { System.out.print("错题如下:"+'\n'); Error(a,b,c,error,k,d,count2); } else { System.out.print("你真棒!全对了!"+'\n'); } } static void Error(int a[ ],int b[ ],int c[ ],int d[ ],int n,int see[ ],int count2[ ]) { int count=0,i,g; Scanner scan=new Scanner(System.in); for(i=0;i<n;i++) { switch(c[d[i]]) { case 0: { System.out.print(d[i]+1+" "+a[d[i]]+"+"+b[d[i]]+"="); g=scan.nextInt( ); if(g!=a[d[i]]+b[d[i]]) { count2[i]++; System.out.print("回答错误!"+" "+count2[i]+'\n'); see[count]=d[i]; d[count]=see[count]; count++; } else { System.out.print("回答正确!"+'\n'); } }break; case 1: { System.out.print(d[i]+1+" "+a[d[i]]+"-"+b[d[i]]+"="); g=scan.nextInt( ); if(g!=a[d[i]]-b[d[i]]) { count2[i]++; System.out.print("回答错误!"+" "+count2[i]+'\n'); see[count]=d[i]; d[count]=see[count]; count++; } else { System.out.print("回答正确!"+'\n'); } }break; case 2: { System.out.print(d[i]+1+" "+a[d[i]]+"*"+b[d[i]]+"="); g=scan.nextInt( ); if(g!=a[d[i]]*b[d[i]]) { count2[i]++; System.out.print("回答错误!"+" "+count2[i]+'\n'); see[count]=d[i]; d[count]=see[count]; count++; } else { System.out.print("回答正确!"+'\n'); } }break; case 3: { System.out.print(d[i]+1+" "+a[d[i]]+"/"+b[d[i]]+"="); g=scan.nextInt( ); if(g!=a[d[i]]/b[d[i]]) { count2[i]++; System.out.print("回答错误!"+" "+count2[i]+'\n'); see[count]=d[i]; d[count]=see[count]; count++; } else { System.out.print("回答正确!"+'\n'); } }break; } } if(count!=0) { System.out.print("还有错题哦,小朋友,再做做吧!"+'\n'); Error(a,b,c,d,count,see,count2); } } public static void main(String[] args) { // TODO 自动生成的方法存根 int n,i,m,d; int [ ]a=new int[100]; int [ ]b=new int[100]; int [ ]c=new int[100]; int [ ]er1=new int[100]; Scanner scan=new Scanner(System.in); System.out.print("Please print the number:"); n=scan.nextInt( ); System.out.print("请输入操作数范围:"); m=scan.nextInt( ); d=scan.nextInt( ); RandomInt(a,b,c,n,m,d); Repeat(a,b,c,n); Exem(a,b,c,er1,n); System.out.print('\n'); } }