系统要求:
1、自动出题,涉及加减乘除四则运算
2、运算为两位数之间
3、减法不能出现负数
4、乘法结果不超过100
5、除法必须整除
6、用户决定出题量
7、用户决定几道题一换行
1 import java.util.Random; 2 import java.util.Scanner; 3 public class Test01 { 4 public static void main(String[] args) { 5 int [][] arr=new int[100000][3]; 6 int [] temp01=new int [3]; 7 Scanner in=new Scanner(System.in); 8 System.out.println("*******给小学生的自动出题系统******"); 9 System.out.println("请输入题量:"); 10 int m=in.nextInt(); 11 System.out.println("请选择几题一换行:"); 12 int n=in.nextInt(); 13 int x=1,y=0,num1,num2,cmp; 14 boolean flag=false; 15 for (int i = 0; i < m; i++) { 16 flag=false; 17 Random r = new Random(); 18 int temp; 19 num1 = r.nextInt(100)+1; 20 num2 = r.nextInt(100)+1; 21 cmp=r.nextInt(4); 22 temp01[0]=num1;//用temp01数组存储随机生成的三个数据 23 temp01[1]=num2; 24 temp01[2]=cmp; 25 for(int j=0;j<y;j++) { 26 if(arr[j]==temp01) { 27 flag=true; 28 break; 29 } 30 } 31 if(flag)//如果重复 32 continue; 33 else 34 { 35 arr[y][0]=num1; 36 arr[y][1]=num2; 37 arr[y][2]=cmp; 38 y++; 39 switch(cmp) { 40 case 0://加 41 System.out.print("第"+x+"个题目:"+num1+"+"+num2+"= "); 42 break; 43 case 1://减 44 if(num1<num2) { 45 temp=num1; 46 num1=num2; 47 num2=temp; 48 } 49 System.out.print("第"+x+"个题目:"+num1+"-"+num2+"= "); 50 break; 51 case 2://乘 52 if(num1<num2) { 53 temp=num1; 54 num1=num2; 55 num2=temp; 56 } 57 while(num1*num2>=100) 58 num1--; 59 System.out.print("第"+x+"个题目:"+num1+"*"+num2+"= "); 60 break; 61 case 3: 62 if(num1<num2) { 63 temp=num1; 64 num1=num2; 65 num2=temp; 66 } 67 while(num1%num2!=0) 68 num2--; 69 System.out.print("第"+x+"个题目:"+num1+"/"+num2+"= "); 70 break; 71 } 72 if(x%n==0) 73 System.out.println(); 74 x++; 75 } 76 } 77 } 78 }