Java中的数字包装器类及其方法是什么?
java.lang包的Number类(抽象)表示可转换为原始类型byte,double,float,int,long和short的数值。
以下是java.lang包的Number类提供的方法。
字节byteValue()
此方法以字节为单位返回指定数字的值。
抽象双doubleValue()
此方法以双精度值形式返回指定数字的值。
抽象浮点数floatValue()
此方法以浮点数形式返回指定数字的值。
抽象整数intValue()
此方法以int形式返回指定数字的值。
抽象长longValue()
此方法以long形式返回指定数字的值。
短shortValue()
此方法以short形式返回指定数字的值。
示例
public class NumberClassExample {
public static void main(String args[]){
Number num = new Integer("25");
System.out.println("Float value of the number: "+num.floatValue());
System.out.println("Double value of the number: "+num.doubleValue());
System.out.println("Long value of the number: "+num.longValue());
System.out.println("Byte value of the number: "+num.byteValue());
System.out.println("Double value of the number: "+num.doubleValue());
System.out.println("Short value of the number: "+num.shortValue());
}
}输出结果
Float value of the number: 25.0 Double value of the number: 25.0 Long value of the number: 25 Byte value of the number: 25 Double value of the number: 25.0 Short value of the number: 25
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短