首页 > 编程知识 正文

Java Double类valueOf方法及示例,java类实例方法

时间:2023-05-03 16:57:29 阅读:247250 作者:4577

Syntax:

句法:

public static Double valueOf (double value); public static Double valueOf (String value); 双类valueOf()方法 (Double class valueOf() method)

valueOf() method is available in java.lang package.

valueOf()方法在java.lang包中可用。

valueOf (double value) method is used to return the Double-object denoted by the given argument (value) is of double type.

valueOf(双精度值)方法用于返回由给定参数(双精度类型)表示的Double-Object。

valueOf (String value) method is used to return the Double-object denoted by the given argument (value) is of String type.

valueOf(字符串值)方法用于返回由给定参数(值)表示的Double对象为String类型。

valueOf (double value) method does not throw an exception at the time of returning an instance.

返回实例时, valueOf(双值)方法不会引发异常。

valueOf (String value) method may throw an exception at the time of returning an instance.

返回一个实例时, valueOf(字符串值)方法可能会引发异常。

NullPointerException: In this exception, if we pass a null value as an argument.NullPointerException:在此异常中,如果我们传递null值作为参数。 NumberFormatException: In this exception, if we don’t pass the number as an argument.NumberFormatException:在此异常中,如果我们不将数字作为参数传递。

valueOf (double value) and valueOf (String value) are the static methods, they are accessible with the class name too and, if we try to access the method with the class object then also we will not get an error.

valueOf(双精度值)和valueOf(字符串值)是静态方法,它们也可以使用类名进行访问,而且,如果尝试使用类对象访问方法,那么也不会出错。

Parameter(s):

参数:

In the first case, double value – represents the value of double type.

在第一种情况下, double value –表示double类型的值。

In the second case, String value – represents the value of String type.

在第二种情况下, 字符串值 –表示字符串类型的值。

Return value:

返回值:

The return type of this method is Double – returns the Double value.

此方法的返回类型为Double-返回Double值。

Example:

例:

// Java program to demonstrate the example // of valueOf() method of Double classpublic class ValueOfDoubleClass { public static void main(String[] args) { // Object initialization Double ob1 = new Double("10.20"); Double ob2 = new Double("20.20"); // Display ob1,ob2 values System.out.println("ob1: " + ob1); System.out.println("ob2: " + ob2); // It returns Double object holding the value // denoted by the given double argument Double value1 = ob1.valueOf(20.10d); // String object initialization for valueOf(String s) String s = "80"; // It returns Double object holding the value // denoted by the given String argument Double value2 = ob2.valueOf(s); // Display result values System.out.println("ob1.valueOf(20.10d): " + value1); System.out.println("ob2.valueOf(s): " + value2); }}

Output

输出量

ob1: 10.2ob2: 20.2ob1.valueOf(20.10d): 20.1ob2.valueOf(s): 80.0

翻译自: https://www.includehelp.com/java/double-class-valueof-method-with-example.aspx

win7电脑文件夹如何加密

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。