Java 教程 Java random() 方法

tylique · 2022-05-24 23:07:45 · 热度: 10

random() 方法用于返回一个随机数,随机数范围为 0.0 =< Math.random < 1.0。

语法

static double random()

参数

  • 这是一个默认方法,不接受任何参数。

返回值

该方法返回 double 值。

实例

public class Test{ public static void main(String args[]){ System.out.println( Math.random() ); System.out.println( Math.random() ); } }

编译以上程序,输出结果为:

0.5444085967267008
0.7960235983184115

查看更多 Java Number & Math 类 相关内容

猜你喜欢:
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册