三十到随机计算题:
1:源程序代码:
package demo;
import java.util.Random;
public class show {
public static void main(String[] args) {
// TODO 自动生成的方法存根
int i=0;
int []x=new int[30];
int []y=new int[30];
int []z=new int[30];
int []m=new int[30];
int []a=new int[30];
int []b=new int[30];
for(i=0;i<30;i++)
{
x[i]=new Random().nextInt(100);
y[i]=new Random().nextInt(100);
z[i]=new Random().nextInt(4);
m[i]=new Random().nextInt(3);
a[i]=new Random().nextInt(5);
b[i]=new Random().nextInt(5);
if(z[i]==0&&(m[i]==0||m[i]==1))
System.out.println(i+1+": "+x[i]+"+"+y[i]+"=");
else if(z[i]==0&&m[i]==2)
{
while(a[i]==0||b[i]==0)
{
a[i]=new Random().nextInt(5);
b[i]=new Random().nextInt(5);
}
System.out.println(i+1+": "+"("+x[i]*a[i]+"/"+x[i]+")"+"+"+"("+y[i]*b[i]+"/"+y[i]+")"+"=");
}
else if(z[i]==1&&(m[i]==0||m[i]==1))
{
if(x[i]>y[i])
System.out.println(i+1+": "+x[i]+"-"+y[i]+"=");
else System.out.println(i+1+": "+y[i]+"-"+x[i]+"=");
}
else if(z[i]==1&&m[i]==2)
{
while(a[i]==0||b[i]==0)
{
a[i]=new Random().nextInt(5);
b[i]=new Random().nextInt(5);
}
if(x[i]>y[i])
System.out.println(i+1+": "+"("+x[i]*a[i]+"/"+x[i]+")"+"-"+"("+y[i]*b[i]+"/"+y[i]+")"+"=");
else System.out.println(i+1+": "+"("+y[i]*b[i]+"/"+y[i]+")"+"-"+"("+x[i]*a[i]+"/"+x[i]+")"+"=");
}
else if(z[i]==2&&(m[i]==0||m[i]==1))
System.out.println(i+1+": "+x[i]+"*"+y[i]+"=");
else if(z[i]==2&&m[i]==2)
{
while(a[i]==0||b[i]==0)
{
a[i]=new Random().nextInt(5);
b[i]=new Random().nextInt(5);
}
System.out.println(i+1+": "+"("+x[i]*a[i]+"/"+x[i]+")"+"*"+"("+y[i]*b[i]+"/"+y[i]+")"+"=");
}
else if(z[i]==3&&(m[i]==0||m[i]==1))
{
while(y[i]==0||b[i]==0|a[i]==0)
{
y[i]=new Random().nextInt(100);
a[i]=new Random().nextInt(10);
b[i]=new Random().nextInt(10);
}
System.out.println(i+1+": "+x[i]+"/"+y[i]+"=");
}
else if(z[i]==3&&m[i]==2)
{
while(y[i]==0||b[i]==0||a[i]==0)
{
y[i]=new Random().nextInt(100);
a[i]=new Random().nextInt(10);
b[i]=new Random().nextInt(10);
}
System.out.println(i+1+": "+"("+x[i]*a[i]+"/"+x[i]+")"+"/"+"("+y[i]*b[i]+"/"+y[i]+")"+"=");
}
}
}
}
运行结果截图:
上课未按时完成原因:上课没有带电脑,有些细节的方面考虑的不太完整,只是一些粗略的想法,假分数部分考虑的不完善。
原文:http://www.cnblogs.com/my1204/p/5252018.html