我是靠谱客的博主 健忘柚子,这篇文章主要介绍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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(127)

评论列表共有 0 条评论

立即
投稿
返回
顶部