该方法用于生成介于0.0和1.0之间的随机数。 范围是:0.0 = 数学, 1.0。 通过使用算术可以实现不同的范围。
句法
- static double random()
参数
这是一个默认方法,不接受参数。
返回值
此方法返回double。
例子
下面是一个使用这个方法的例子 -
- class Example {
- static void main(String[] args) {
- System.out.println( Math.random() );
- System.out.println( Math.random() );
- }
- }
当我们运行上面的程序,我们将得到以下结果 -
- 0.0543333676591804
- 0.3223824169137166
转载本站内容时,请务必注明来自W3xue,违者必究。