二柱子出的题

源代码:

package 随机数;

public class random1 {
private int a;
private int b;
private int c;
private int d;
random1()
{

}
random1(int a,int b)
{

}
random1(int a,int b,int c)
{

}
random1(int a,int b,int c,int d)
{

}
public int getA() {
return a;
}
public void setA(int a) {
this.a = a;
}
public int getB() {
return b;
}
public void setB(int b) {
this.b = b;
}
public int getC() {
return c;
}
public void setC(int c) {
this.c = c;
}
public int getD() {
return d;
}
public void setD(int d) {
this.d = d;
}

}

 

 

 

 

package 随机数;
import java.util.Scanner;
import java.util.ArrayList;
public class Random {
public static ArrayList <random1> array = new ArrayList <random1>();
public static void main(String[] args) {
// TODO Auto-generated method stub
date();
System.out.println("请输入操作数:");
System.out.println("1. 2");
System.out.println("2. 3");
System.out.println("3. 4");
Scanner sc = new Scanner(System.in);
int k=sc.nextInt();
switch(k)
{
case 1:
System.out.println("如果有乘除法请输入1否则输入0");
int s=sc.nextInt();
System.out.println("如果有括号请输入1否则输入0");
int m=sc.nextInt();
if(s==1&&m==1)
{
System.out.println("请输入打印的数量");
int n=sc.nextInt();
for(int i=0;i<n;i++)
{
random1 B = array.get(i);
int c = (int) (Math.random() * 4 + 1);
switch(c)
{
case 1:
System.out.println(B.getA()+"+"+B.getB()+"=");
break;
case 2:
System.out.println(B.getA()+"-"+B.getB()+"=");
break;
case 3:
System.out.println(B.getA()+"*"+B.getB()+"=");
break;
case 4:
System.out.println(B.getA()+"/"+B.getB()+"=");
break;
}

}
}
else
{
System.out.println("请输入打印的数量");
int n=sc.nextInt();
for(int i=0;i<n;i++)
{
random1 B = array.get(i);
int c = (int) (Math.random() * 2 + 1);
switch(c)
{
case 1:
System.out.println(B.getA()+"+"+B.getB()+"=");
break;
case 2:
System.out.println(B.getA()+"-"+B.getB()+"=");
break;
}
}
}
break;
case 2:
System.out.println("如果有乘除法请输入1否则输入0");
int s1=sc.nextInt();
System.out.println("如果有括号请输入1否则输入0");
int m1=sc.nextInt();
if(s1==1&&m1==1)
{
System.out.println("请输入打印的数量");
int n=sc.nextInt();
for(int i=0;i<n;i++)
{
random1 B = array.get(i);
int c = (int) (Math.random() * 4 + 1);
switch(c)
{
case 1:
System.out.println(B.getA()+"+("+B.getB()+"*"+B.getC()+")"+"=");
break;
case 2:
System.out.println(B.getA()+"-"+B.getB()+"/"+B.getC()+"=");
break;
case 3:
System.out.println(B.getA()+"*"+B.getB()+"+"+B.getC()+"=");
break;
case 4:
System.out.println("("+B.getA()+"/"+B.getB()+")-"+B.getC()+"=");
break;
}

}
}
else
{
System.out.println("请输入打印的数量");
int n=sc.nextInt();
for(int i=0;i<n;i++)
{
random1 B = array.get(i);
int c = (int) (Math.random() * 4 + 1);
switch(c)
{
case 1:
System.out.println(B.getA()+"+"+B.getB()+"-"+B.getC()+"=");
break;
case 2:
System.out.println(B.getA()+"-"+B.getB()+"-"+B.getC()+"=");
break;
case 3:
System.out.println(B.getA()+"+"+B.getB()+"+"+B.getC()+"=");
break;
case 4:
System.out.println(B.getA()+"-"+B.getB()+"+"+B.getC()+"=");
break;
}

}
}
break;
case 3:
System.out.println("如果有乘除法请输入1否则输入0");
int s2=sc.nextInt();
System.out.println("如果有括号请输入1否则输入0");
int m2=sc.nextInt();
if(s2==1&&m2==1)
{
System.out.println("请输入打印的数量");
int n=sc.nextInt();
for(int i=0;i<n;i++)
{
random1 B = array.get(i);
int c = (int) (Math.random() * 4 + 1);
switch(c)
{
case 1:
System.out.println(B.getA()+"+("+B.getB()+"*"+B.getC()+")"+"/"+B.getD()+"=");
break;
case 2:
System.out.println(B.getA()+"-"+B.getB()+"/"+B.getC()+"*"+B.getD()+"=");
break;
case 3:
System.out.println(B.getA()+"*"+B.getB()+"+"+B.getC()+"-"+B.getD()+"=");
break;
case 4:
System.out.println("("+B.getA()+"/"+B.getB()+")-"+B.getC()+"*"+B.getD()+"=");
break;
}

}
}
else
{
System.out.println("请输入打印的数量");
int n=sc.nextInt();
for(int i=0;i<n;i++)
{
random1 B = array.get(i);
int c = (int) (Math.random() * 4 + 1);
switch(c)
{
case 1:
System.out.println(B.getA()+"+"+B.getB()+"-"+B.getC()+"+"+B.getD()+"=");
break;
case 2:
System.out.println(B.getA()+"-"+B.getB()+"-"+B.getC()+"-"+B.getD()+"=");
break;
case 3:
System.out.println(B.getA()+"+"+B.getB()+"+"+B.getC()+"-"+B.getD()+"=");
break;
case 4:
System.out.println(B.getA()+"-"+B.getB()+"+"+B.getC()+"-"+B.getD()+"=");
break;
}

}
}
break;

}

}

public static void date()
{
int []a =new int [100];
int []b =new int [100];
int []c =new int [100];
int []d =new int [100];

System.out.println(" 1.1-10");
System.out.println(" 2.1-100");
System.out.println(" 3.1-1000");
System.out.println(" 4.1-10000");
System.out.println("请选择数值范围");
Scanner sc = new Scanner(System.in);
int k=sc.nextInt();
switch(k)
{
case 1:
for(int i=0;i<100;i++)
{
a[i]=(int)(Math.random()*10);
b[i]=(int)(Math.random()*10);
c[i]=(int)(Math.random()*10);
d[i]=(int)(Math.random()*10);
}
for(int i=0;i<100;i++)
{
for(int j=1;j<100;j++)
{
if(a[i]==a[j]||b[i]==b[j]||c[i]==c[j]||d[i]==d[j])
{
a[i]=(int)(Math.random()*10);
b[i]=(int)(Math.random()*10);
c[i]=(int)(Math.random()*10);
d[i]=(int)(Math.random()*10);
}
}
}
for(int i=0;i<100;i++)
{
random1 A = new random1();
A.setA(a[i]);
A.setB(b[i]);
A.setC(c[i]);
A.setD(d[i]);
array.add(A);
}
break;
case 2:
for(int i=0;i<100;i++)
{
a[i]=(int)(Math.random()*100);
b[i]=(int)(Math.random()*100);
c[i]=(int)(Math.random()*100);
d[i]=(int)(Math.random()*100);
}
for(int i=0;i<100;i++)
{
for(int j=1;j<100;j++)
{
if(a[i]==a[j]||b[i]==b[j]||c[i]==c[j]||d[i]==d[j])
{
a[i]=(int)(Math.random()*100);
b[i]=(int)(Math.random()*100);
c[i]=(int)(Math.random()*100);
d[i]=(int)(Math.random()*100);
}
}
}
for(int i=0;i<100;i++)
{
random1 A = new random1();
A.setA(a[i]);
A.setB(b[i]);
A.setC(c[i]);
A.setD(d[i]);
array.add(A);
}
break;
case 3:
for(int i=0;i<100;i++)
{
a[i]=(int)(Math.random()*1000);
b[i]=(int)(Math.random()*1000);
c[i]=(int)(Math.random()*1000);
d[i]=(int)(Math.random()*1000);
}
for(int i=0;i<100;i++)
{
for(int j=1;j<100;j++)
{
if(a[i]==a[j]||b[i]==b[j]||c[i]==c[j]||d[i]==d[j])
{
a[i]=(int)(Math.random()*1000);
b[i]=(int)(Math.random()*1000);
c[i]=(int)(Math.random()*1000);
d[i]=(int)(Math.random()*1000);
}
}
}
for(int i=0;i<100;i++)
{
random1 A = new random1();
A.setA(a[i]);
A.setB(b[i]);
A.setC(c[i]);
A.setD(d[i]);
array.add(A);
}
break;
case 4:
for(int i=0;i<100;i++)
{
a[i]=(int)(Math.random()*10000);
b[i]=(int)(Math.random()*10000);
c[i]=(int)(Math.random()*10000);
d[i]=(int)(Math.random()*10000);
}
for(int i=0;i<100;i++)
{
for(int j=1;j<100;j++)
{
if(a[i]==a[j]||b[i]==b[j]||c[i]==c[j]||d[i]==d[j])
{
a[i]=(int)(Math.random()*10000);
b[i]=(int)(Math.random()*10000);
c[i]=(int)(Math.random()*10000);
d[i]=(int)(Math.random()*10000);
}
}
}
for(int i=0;i<100;i++)
{
random1 A = new random1();
A.setA(a[i]);
A.setB(b[i]);
A.setC(c[i]);
A.setD(d[i]);
array.add(A);
}
break;
}
}
}

运行截图:

 

posted @ 2021-09-19 20:11  权。  阅读(31)  评论(0编辑  收藏  举报