标签:com str todo stat nbsp min eth and oid
1.定义SuiJi类包括
(1)shuZi()用来生成随机数;
(2)fuHao()用来生成符号;随机数生成1、2、3、4‘分别对应“+”、“-”、“×"、”÷“
2.主类分别调用两次suiJi()生成四则运算的数字;和一次随机符号函数;
3.缺陷:没有考虑到0为分母这个特殊情况;
4代码:
package shuju;
import java.util.Random;
public class shuju {
public static void main(String[] args) {
// TODO Auto-generated method stub
SuiJi suiji=new SuiJi();
Long k = 9223372036854775807L;
for(long i=1;i<=k;i++)
{
System.out.print("\n"+i+"--"+suiji.shuZi()+suiji.fuHao()+suiji.shuZi()+"=");
}
}
}
//int a=ran.nextInt(max)%(max-min+1) + min;
class SuiJi{
Random ran=new Random();
public int shuZi(){
int a=ran.nextInt(10);
if(a==0) {
return shuZi();
}else
return a;
}
public String fuHao(){
int k=ran.nextInt(4);
if(k==1) {
return "+";
}if(k==2) {
return "-";
}if(k==3) {
return "×";
}
return "÷";
}
}
截图:
标签:com str todo stat nbsp min eth and oid
原文地址:http://www.cnblogs.com/liushiqiang123/p/7955802.html