首先思路:先试用了rand产生随机数种子来产生随机数,然后定义了十个数组分别来进行查重和存储数据
package Ktang;
import java.util.Random;
import java.util.Scanner;
public class Student {
static final int x = 100000;
public static void main(String[] args) {
// TODO Auto-generated method stub
Random r = new Random(1);
int i=0;
int j=0;
Scanner sc=new Scanner(System.in);
int a;
int b;
int c=0;
int date1[]=new int[x];
int date2[]=new int[x];
int jia1[]=new int[x];
int jia2[]=new int[x];
int jian1[]=new int[x];
int jian2[]=new int[x];
int cheng1[]=new int[x];
int cheng2[]=new int[x];
int chu1[]=new int[x];
int chu2[]=new int[x];
System.out.println("请输入你想要多少的题数和一行个数");
a=sc.nextInt();
b=sc.nextInt();
for(i=0;i<a;i++)
{
int ran1 = r.nextInt(100);
int ran2 = r.nextInt(100);
date1[i]=ran1;
date2[i]=ran2;
jia1[i]= ran1;
jia2[i]=ran2;
jian1[i]=ran1;
jian2[i]=ran2;
cheng1[i]=ran1;
cheng2[i]=ran2;
chu1[i]=ran1;
chu2[i]=ran2;
}
while(c<=a)
{
c++;
for(i=1;i<=b;i++)
{
int ran2 = r.nextInt(3);
System.out.println("第"+i+"个");
switch(ran2)
{
case 0 :for(j=a;j>=0;j--)
{if(jia1[j]!=date1[i]&&jia2[j]!=date2[i])
{System.out.println(date1[i]+"+"+date2[i]+"=");}}
break;
case 1 :for(j=a;j>=0;j--)
{if(jian1[j]!=date1[i]&&jian2[j]!=date2[i])
{if(date1[i]>=date2[i])
{
System.out.println(date1[i]+"-"+date2[i]+"=");
break;}
else
{System.out.println(date1[i]+"-"+date2[i]+"=");
break;
}}}
case 2 :for(j=a;j>=0;j--)
{if(cheng1[j]!=date1[i]&&cheng2[j]!=date2[i])
System.out.println(date1[i]+"*"+date2[i]+"=");
break;}
case 3 :
for(j=a;j>=0;j--)
{if(chu1[j]!=date1[i]&&chu2[j]!=date2[i])
System.out.println(date1[i]+"/"+date2[i]+"=");
break;
}
}
}
}
}
}