Java Double shortValue()方法及示例

来源:这里教程网 时间:2026-02-17 20:52:53 作者:

Java Double shortValue()方法及示例

Double类的 shortValue() 方法是一个内置的方法,用于将调用对象指定的值在类型转换后返回为短值。

语法

DoubleObject.shortValue()

返回值: 它将DoubleObject的值作为 short 返回 。

以下程序说明了Java中的shortValue()方法:

程序1:

// Java code to demonstrate// Double shortValue() method class GFG {    public static void main(String[] args)    {         // Double value        Double a = 17.47;         // wrapping the Double value        // in the wrapper class Double        Double b = new Double(a);         // shortValue of the Double Object        short output = b.shortValue();         // print shorting the output        System.out.println("Short value of "                           + b + " is : " + output);    }}

输出

Short value of 17.47 is : 17

程序2:

// Java code to demonstrate// Double shortValue() method class GFG {    public static void main(String[] args)    {         String value = "54.1";         // wrapping the Double value        // in the wrapper class Double        Double b = new Double(value);         // shortValue of the Double Object        short output = b.shortValue();         // print shorting the output        System.out.println("Short value of "                           + b + " is : " + output);    }}

输出

Short value of 54.1 is : 54

相关推荐