📌  相关文章
📜  Java中的 ChoiceFormat nextDouble(double) 方法及示例

📅  最后修改于: 2022-05-13 01:54:29.318000             🧑  作者: Mango

Java中的 ChoiceFormat nextDouble(double) 方法及示例

Java.text.ChoiceFormat类的nextDouble(double)方法用于获取刚好大于指定 double 值的 double 值。

句法:

public static final double nextDouble(double d)

参数:此方法接受双精度值d作为返回下一个双精度值的参数。
返回值:此方法返回一个刚好大于传递的双精度的双精度值。
下面是说明nextDouble()方法的示例:
示例 1:

Java
// Java program to demonstrate
// nextDouble() method
 
import java.text.*;
import java.util.*;
import java.io.*;
 
public class GFG {
    public static void main(String[] argv)
    {
        // getting double value just
        // greater than the passed value
        // using nextDouble() method
        double value
            = ChoiceFormat.nextDouble(22);
 
        // display the result
        System.out.print("Next greater double"
                         + " value than 22: "
                         + value);
    }
}


Java
// Java program to demonstrate
// nextDouble() method
 
import java.text.*;
import java.util.*;
import java.io.*;
 
public class GFG {
    public static void main(String[] argv)
    {
        // calling getValue() method
        getValue(1.23d);
        getValue(10d);
        getValue(-12d);
        getValue(1.2f);
        getValue(50);
    }
 
    // defining getValue() method
    public static void getValue(double doub)
    {
 
        // getting double value just
        // greater than the passed value
        // using nextDouble() method
        double value
            = ChoiceFormat.nextDouble(doub);
 
        // display the result
        System.out.println("Next greater double"
                         + " value than "
                         + doub + ": " + value);
    }
}


输出:
Next greater double value than 22: 22.000000000000004

示例 2:

Java

// Java program to demonstrate
// nextDouble() method
 
import java.text.*;
import java.util.*;
import java.io.*;
 
public class GFG {
    public static void main(String[] argv)
    {
        // calling getValue() method
        getValue(1.23d);
        getValue(10d);
        getValue(-12d);
        getValue(1.2f);
        getValue(50);
    }
 
    // defining getValue() method
    public static void getValue(double doub)
    {
 
        // getting double value just
        // greater than the passed value
        // using nextDouble() method
        double value
            = ChoiceFormat.nextDouble(doub);
 
        // display the result
        System.out.println("Next greater double"
                         + " value than "
                         + doub + ": " + value);
    }
}
输出:
Next greater double value than 1.23: 1.2300000000000002
Next greater double value than 10.0: 10.000000000000002
Next greater double value than -12.0: -11.999999999999998
Next greater double value than 1.2000000476837158: 1.200000047683716
Next greater double value than 50.0: 50.00000000000001

参考: https://docs.oracle.com/javase/9/docs/api/ Java/text/ChoiceFormat.html#nextDouble-double-