随机问题! Random rand = new Random(System.currentTimeMillis());rand.nextInt() % 3; // -2 -1 0 1 2rand.nextInt() % 2; // -1 0 1 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 没有办法用nextDouble(),因为1.0是不包括的,只好找了下面一条变通的办法,你可以试试.int digits = 3;(rand.nextInt() % ( 3 * Math.pow(10,digits) + 1) ) / Math.pow(10,digits) 呵呵,谢谢你!我做了个测试,确实没问题public static void main(String[] args) { int digits = 3; Random rand = new Random(System.currentTimeMillis()); for (int i=0;i<20000;i++) { double asdf = (rand.nextInt() % ( 2 * Math.pow(10,digits) + 1) ) / Math.pow(10,digits); if(asdf==2.0) { System.out.println("OK"); break; } } } SSH2协议获取防火墙Config的问题. 循环来创建JButton对象 关于getText()与equals()的问题 请教:数据库连接池是不是这么写的? jni的问题,发现VC和JAVA真是格格不入阿 菜鸟请教!急用! 请问java中 >>> 这个符号的用法? 刚刚接触JBUILDER,急问2个问题 有哪位大虾用过eclipse,ant,cvs! String.valueof(11);和String 是= ""+11;的区别 我写了applet程序,上面有不少的textbox combobox,老板要求用tab键切换焦点。 键盘与多线程编程问题
int digits = 3;
(rand.nextInt() % ( 3 * Math.pow(10,digits) + 1) ) / Math.pow(10,digits)
public static void main(String[] args)
{
int digits = 3;
Random rand = new Random(System.currentTimeMillis());
for (int i=0;i<20000;i++)
{
double asdf = (rand.nextInt() % ( 2 * Math.pow(10,digits) + 1) ) / Math.pow(10,digits);
if(asdf==2.0)
{
System.out.println("OK");
break;
}
}
}