java.lang.Number.byteValue()是java中的内置方法,它以字节为单位返回指定数字的值。这可能涉及舍入或截断。
用法:
public byte byteValue()
参数:该方法不带任何参数。
返回值:转换为字节类型后,此方法返回此对象表示的数值。
以下示例程序旨在说明Number.byteValue()方法的使用:
示例1:
// Java program to illustrate the
// Number.byteValue() method
public class gfg {
public static void main(String[] args)
{
// Get a number as integer
Integer x = new Integer(12345786);
// Print bytevalue()
System.out.println(x.byteValue());
// Get a number as float
Float y = new Float(9145876f);
// Print bytevalue()
System.out.println(y.byteValue());
}
}
输出:
-70
20
示例2:
// Java program to illustrate the
// Number.byteValue() method
public class gfg {
public static void main(String[] args)
{
// Get a number as integer
Integer x = new Integer(123);
// Print bytevalue()
System.out.println(x.byteValue());
// Get a number as float
Float y = new Float(76f);
// Print bytevalue()
System.out.println(y.byteValue());
}
}
输出:
123
76