标签:记录 break *** out and 显示 random next ase
package Szys;
import java.util.Random;
import java.util.Scanner;
public class szys {
public static void main(String[] args) {
int [][] arr=new int[10000][3];//存储生成的每个题目,避免重复出现
int [] temp01=new int [3];
Scanner in=new Scanner(System.in);
System.out.println("*******随机生成指定数量四则运算系统******");
System.out.println("请输入题量:");
int m=in.nextInt();
System.out.println("请选择一行显示多少题目:");
int n=in.nextInt();
int x=1,y=0,num1,num2,cmp;
boolean flag=false;//定义布尔类型变量用来记录是否重复
for (int i = 0; i < m; i++) {
flag=false;
Random r = new Random();//生成随机数
int temp;
num1 = r.nextInt(100)+1;
num2 = r.nextInt(100)+1;//生成两数1~100以内,避免除0情况
cmp=r.nextInt(4);//生成0~4,表示加减乘除
temp01[0]=num1;//用temp01数组存储随机生成的三个数据
temp01[1]=num2;
temp01[2]=cmp;
for(int j=0;j<y;j++) {//查重
if(arr[j]==temp01) {
flag=true;
break;
}
}
if(flag)//如果重复
continue;
else//如果不重复,则存入数组
{
arr[y][0]=num1;
arr[y][1]=num2;
arr[y][2]=cmp;
y++;
switch(cmp) {
case 0://加
System.out.print("第"+x+"个题目:"+num1+"+"+num2+"= ");
break;
case 1://减
if(num1<num2) {
temp=num1;
num1=num2;
num2=temp;
}
System.out.print("第"+x+"个题目:"+num1+"-"+num2+"= ");
break;
case 2://乘
if(num1<num2) {
temp=num1;
num1=num2;
num2=temp;
}
while(num1*num2>=100)
num1--;
System.out.print("第"+x+"个题目:"+num1+"*"+num2+"= ");
case 3:
if(num1<num2) {
temp=num1;
num1=num2;
num2=temp;
}
while(num1%num2!=0)
num2--;
System.out.print("第"+x+"个题目:"+num1+"/"+num2+"= ");
break;
}
if(x%n==0)//换行
System.out.println();
x++;
}
}
}
}
标签:记录 break *** out and 显示 random next ase
原文地址:https://www.cnblogs.com/4603a/p/14644581.html