2009-07-09 15:54:10
原创作品,允许转载,转载时请务必以超链接形式标明文章
原始出处 、作者信息和本声明。否则将追究法律责任。
http://77857.blog.51cto.com/67857/175769
Byte/byte总结
说明:如有问题,请给本人更正。
Byte
类将基本类型
byte
的值包装在一个对象中。一个
Byte
类型的对象只包含一个类型为
byte
的字段。
此外,该类还为
byte
和
String
的相互转换提供了几种方法,并提供了处理
byte
时非常有用的其他一些常量和方法。
byte表示一种数据类型,当byte类型相加转换为int,测试代码
保存
byte
类型可取的最大值,即 2
7-1。
package com.youngmaster.bo;
public class BadArithmetic {
static byte addOneAndOne() {
byte a = 1;
byte b = 1;
byte c = (byte)(a + b);
//byte c = (a + b);
return c ;
}
public static void main(String args[]){
BadArithmetic bat=new BadArithmetic();
System.out.println(bat.addOneAndOne());
System.out.println(Byte.MAX_VALUE);
System.out.println(Byte.MIN_VALUE);
System.out.println(Byte.SIZE);
System.out.println(Byte.class);
}
static byte addOneAndOne() {
byte a = 1;
byte b = 1;
byte c = (byte)(a + b);
//byte c = (a + b);
return c ;
}
public static void main(String args[]){
BadArithmetic bat=new BadArithmetic();
System.out.println(bat.addOneAndOne());
System.out.println(Byte.MAX_VALUE);
System.out.println(Byte.MIN_VALUE);
System.out.println(Byte.SIZE);
System.out.println(Byte.class);
}
}
输出结果如下:
2
127
-128
8
class java.lang.Byte
127
-128
8
class java.lang.Byte
本文出自 “gjhgkh” 博客,请务必保留此出处http://77857.blog.51cto.com/67857/175769
public class BadArithmetic {
static byte addOneAndOne() {
byte a = 1;
byte b = 1;
byte c = (byte)(a + b);
//byte c = (a + b);
return c ;
}
public static void main(String args[]){
BadArithmetic bat=new BadArithmetic();
System.out.println(bat.addOneAndOne());
System.out.println(Byte.MAX_VALUE);
System.out.println(Byte.MIN_VALUE);
System.out.println(Byte.SIZE);
System.out.println(Byte.class);
}
}
/*
2
127
-128
8
class java.lang.Byte
请按任意键继续. . .
*/