Java中的字节类字段示例
Byte类将原始类型byte的值包装在对象中。
以下是字节类的字段-
静态字节MAX_VALUE-该常量保持一个字节可以具有的最大值27-1。
静态字节MIN_VALUE-此常量保持一个字节可以具有的最小值-27。
staticintSIZE-这是用来表示二进制补码二进制形式的字节值的位数。
静态Class<Byte>TYPE-这是表示原始类型字节的Class实例。
示例
现在让我们看一个例子-
import java.lang.*;
public class Demo {
public static void main(String[] args){
Byte b1, b2;
int i1, i2;
b1 = new Byte("1");
b2 = Byte.MIN_VALUE;
i1 = b1.intValue();
i2 = b2.intValue();
String str1 = "int value of Byte " + b1 + " is " + i1;
String str2 = "int value of Byte " + b2 + " is " + i2;
System.out.println( str1 );
System.out.println( str2 );
}
}输出结果
这将产生以下输出-
int value of Byte 1 is 1 int value of Byte -128 is -128
示例
现在让我们来看另一个示例-
import java.lang.*;
public class Demo {
public static void main(String[] args){
Byte b1, b2;
String s1, s2;
b1 = new Byte("-10");
b2 = Byte.MIN_VALUE;
System.out.println("Number of bits in b1 = "+b1.SIZE );
System.out.println("Number of bits in b2 = "+b2.SIZE );
s1 = b1.toString();
s2 = b2.toString();
String str1 = "String value of Byte " + b1 + " is " + s1;
String str2 = "String value of Byte " + b2 + " is " + s2;
System.out.println( str1 );
System.out.println( str2 );
}
}输出结果
这将产生以下输出-
Number of bits in b1 = 8 Number of bits in b2 = 8 String value of Byte -10 is -10 String value of Byte -128 is -128
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短