package szyszff;
import java.util.Random;
import java.util.Scanner;
public class windowszhu {
public static void main(String[] args) {
System.out.println("请输入打印的题目数:");
Scanner sc=new Scanner(System.in);
int e=sc.nextInt();
System.out.println("请输入操作数的个数:");
int operation=sc.nextInt();
System.out.println("请输入是否有乘除法:");
System.out.println("请输入Y/N");
char cc=sc.next().charAt(0);
System.out.println("请输入是否有括号:");
System.out.println("请输入Y/N");
char kh=sc.next().charAt(0);
System.out.println("请输入操作数的下限:");
int min=sc.nextInt();
System.out.println("请输入操作数的上限:");
int max=sc.nextInt();
int[]b = new int[operation];
int[]c=new int[operation];
int[]a=new int[operation];
int[]d=new int[operation];
int sum=0;
Random r=new Random();
int num=1;
for(int y=0;y<e+sum;y++) {
for(int f=0;f<operation;f++){
a[f]=b[f];
d[f]=c[f];
}
for(int j=0;j<operation;j++) {
czs(cc,operation,b,c,max,min);//生成随机数
if(kh=='Y') {
int s=r.nextInt((operation-1)-1+1)+1;
int p=r.nextInt((operation-1)-s+1)+s;
for(int i=0;i<operation;i++) {//生成运算式子
if(s==i) {
System.out.print('(');
}
System.out.print(b[i]);
if(p==i) {
System.out.print(')');
}
if(i<operation-1) {
System.out.print(js(c[i]));
}
}
System.out.println('=');
}
else {
for(int w=0;w<operation;w++) {
System.out.print(b[w]);
if(w<operation-1) {
System.out.print(js(c[w]));
}
}
System.out.println('=');
}
}
sum=jccf(operation,a,b,c,d);
if(num==1) {
sum++;
continue;
}
}
}
public static char js(int c) {//转化运算符号
char a=0;
switch(c) {
case 0:a='+';
break;
case 1:a='-';
break;
case 2:a='*';
break;
case 3:a='/';
break;
}
return a;
}
public static int jccf(int operation,int a[],int b[],int c[],int d[]) {//避免重复
int n=0;
int[]s1 = new int[operation];
int[]s2=new int[operation];
int[]s3=new int[operation];
int[]s4=new int[operation];
for(int i=0;i<operation-1;i++) {
s1[i]=a[i];
s2[i]=b[i];
s3[i]=c[i];
s4[i]=d[i];
}
for(int k=0;k<operation;k++) {
if(s1[k]==s2[k]&&s4[k]==s3[k]) {
continue;
}
else {
n=1;
break;
}
}
return n;
}
public static void czs(char cc,int operation,int b[],int c[],int max,int min) {//生成随机数
Random l=new Random();
for(int j=0;j<operation;j++) {
//System.out.println(1123);
b[j]=l.nextInt(max-min+1)+min;
if(cc=='Y') {
c[j]= l.nextInt(4);
}
else {
c[j]= l.nextInt(2);
}
}
}
}
附:
Math.ads(x)等于|x|;