java short float_Java Short floatValue()用法及代码示例
Short類的java.lang.Short.floatValue()方法是Java中的內置方法,用于將Short對象的值作為浮點數返回。
用法:
public float floatValue()
返回類型:它返回ShortObject的值作為float。
下面是Java中floatValue()方法的實現:
示例1:
// Java code to demonstrate
// Short floatValue() method
class GFG {
public static void main(String[] args)
{
// Short value
Short a = 17;
// wrapping the Short value
// in the wrapper class Short
Short b = new Short(a);
// floatValue of the Short Object
float output = b.floatValue();
// printing the output
System.out.println("Float value of "
+ a + " is : " + output);
}
}
輸出:
Float value of 17 is : 17.0
示例2:
// Java code to demonstrate
// Short floatValue() method
class GFG {
public static void main(String[] args)
{
String value = "17";
// wrapping the Short value
// in the wrapper class Short
Short b = new Short(value);
// floatValue of the Short Object
float output = b.floatValue();
// printing the output
System.out.println("Float value of "
+ b + " is : " + output);
}
}
輸出:
Float value of 17 is : 17.0
總結
以上是生活随笔為你收集整理的java short float_Java Short floatValue()用法及代码示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java正则 找出数字_Java使用正则
- 下一篇: TestDisk 数据恢复 重建分区表恢