日期:2014-05-20 浏览次数:20819 次
public class Tbyte{ public static void main(String args[]){ Byte b1=new Byte("a"); int i1; i1=b1.intValue(); System.out.println(i1); } }
public class test { public static void main(String args[]) { Byte b1 = new Byte((byte)'a'); int i1; i1 = b1.intValue(); System.out.println(i1); } }
------解决方案--------------------
String str = "127";//取值范围:"-128","-127",...."-2","-1","0","1","2",....,"126","127" Byte b1 = new Byte(str);//因为它只有八个二进制位,十进制形式为大于-128小于127 int i1; i1 = b1.intValue(); /* Constructs a newly allocated Byte object that represents the byte value indicated by the String parameter. The string is converted to a byte value in exactly the manner used by the parseByte method for radix 10. */