Java里的Random类怎样实现在true和false里打印输出true的概率为70%?

来源:百度知道 编辑:UC知道 时间:2024/05/11 17:00:19
RT
2楼的有个错误.必须将Math.random()给一个值.要不然会随机两次.造成打印错误.不过你的思路完全正确.

package com;

public class TestRandom {

public static void main(String[] args) {
if(Math.random()>0&&Math.random()<=0.7) {
System.out.print(Math.random());
System.out.println("true");
}else {
System.out.println("false");
}
}
}

啥意思?没看懂@@@@!