本文共 1601 字,大约阅读时间需要 5 分钟。
nextfloat
nextFloat() method is available in java.util package.
nextFloat()方法在java.util包中可用。
nextFloat() method is used to generate the next pseudo-random float value between the range 0.0 and 1.0 from this Random Value Generator.
nextFloat()方法用于从该随机值生成器生成介于0.0和1.0之间的下一个伪随机浮点值。
nextFloat() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
nextFloat()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
nextFloat() method does not throw an exception at the time of returning float.
返回float时, nextFloat()方法不会引发异常。
Syntax:
句法:
public float nextFloat();
Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
The return type of the method is float, it returns next pseudo-random distributed float value between the given range from this Random Generator.
方法的返回类型为float ,它从该Random Generator返回给定范围之间的下一个伪随机分布float值。
Example:
例:
// Java program to demonstrate the example // of float nextFloat() method of // Randomimport java.util.*;public class NextFloatOfRandom { public static void main(String args[]) { // Instantiates Random object Random ran = new Random(); // By using nextFloat() method is // to return float pseudo-random // value between 0.0 and 1.0 by // using Random Value Generator float val = ran.nextFloat(); // Display System.out.println("ran.nextFloat(): " + val); }}
Output
输出量
RUN 1:ran.nextFloat(): 0.89347947RUN 2:ran.nextFloat(): 0.48533785RUN 3:ran.nextFloat(): 0.2989604
翻译自:
nextfloat
转载地址:http://lxtzd.baihongyu.com/