package Test2333; import java.util.Random; import java.util.Timer; import java.util.TimerTask; import java.util.Scanner; public class daily1 { //设置时长(秒) static int countDownTime=100; public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a[]=new int[100]; int b[]=new int[100]; int result[]=new int[100]; int answer; int wrong=0; float root=0; int num=1;//题目数; Timer timer=new Timer(); TimerTask task=new TimerTask() { @Override public void run() { if(countDownTime!=0){ countDownTime--; } } }; timer.schedule(task,0,1000); do{ ti(num,result,a,b); num++; answer=sc.nextInt(); System.out.println("剩余时间:"+countDownTime); if(countDownTime==0)break; if(answer!=result[num-1]){ wrong++; System.out.println("正确答案是:"+result[num-1]); } } while(num<=30); if(num<=30){ for(int i=num;i<=30;i++){ ti(num,result,a,b); num++; wrong++; System.out.println("正确答案是:"+result[num-1]); } } root=(float)(30-wrong)/30; System.out.println("错题数:"+wrong); System.out.println("正确率:"+root*100+"%"); } //判断是否为负数 public static int fu(int a){ if(a<0) a=-1*a; if(a<10) a=a+10; return a; } //生成一个题目 public static void ti(int num,int result[],int a[],int b[]){ boolean check=false; Random r=new Random(); a[num]=r.nextInt()%100; b[num]=r.nextInt()%100; int m=r.nextInt()%9; a[num]=fu(a[num]); b[num]=fu(b[num]); if(m<0){ m=-1*m; } switch(m){ case 0: for(int i=0;i<num;i++){ if(a[i]==a[num]&&b[i]==b[num]) check=true; } if(!check){ System.out.println(num+"、"+a[num]+"+"+b[num]+"=");result[num]=a[num]+b[num];} num++; break; case 6: case 1: for(int i=0;i<num;i++){ if(a[i]==a[num]&&b[i]==b[num]) check=true; } if(a[num]<b[num]) check=true; if(!check){ System.out.println(num+"、"+a[num]+"-"+b[num]+"=");result[num]=a[num]-b[num]; num++;} break; case 4: case 2: for(int i=0;i<num;i++){ if(a[i]==a[num]&&b[i]==b[num]) check=true; } if(a[num]*b[num]>1000) check=true; if(!check){ System.out.println(num+"、"+a[num]+"*"+b[num]+"=");result[num]=a[num]*b[num]; num++;} break; case 8: case 7: case 5: case 3: for(int i=0;i<num;i++){ if(a[i]==a[num]&&b[i]==b[num]) check=true; } if(a[num]%b[num]!=0) check=true; if(!check){ System.out.println(num+"、"+a[num]+"/"+b[num]+"=");result[num]=a[num]/b[num]; num++;} break; } if(check){ ti(num,result,a,b); } } }
标签:答题,19,System,int,num,result,new,2023.9,countDownTime From: https://www.cnblogs.com/muzhaodi/p/17715702.html