package cn.itast.chap.stttt01.包装类;
import java.io.IOException;
import java.lang.Byte;
import java.lang.Integer;
public class IntegerTest002 {
public static void main(String[] args) throws NumberFormatException{
//获取int类型的最大值和最小值
System.out.println("int 最小值"+Integer.MIN_VALUE);
System.out.println("int 最大值"+Integer.MAX_VALUE);
System.out.println();
//获取byte类型的最大值和最小值
System.out.println("byte最小值"+Byte.MIN_VALUE);
System.out.println("byte最大值"+Byte.MAX_VALUE);
//创建Integer类型对象
Integer i1 = new Integer(10);//int ---> Integer
Integer i2 = new Integer("12334");//Stirng--->int
System.out.println("i1 = "+ i1+"\ti2 = "+i2);
//以下程序编译可以通过,但是运行时会报异常,数字格式化异常
//虽然可以将字符转成Integer类型,但是该字符串也必须是"数字字符串";
Integer i3 = new Integer("aaaa");
System.out.println(i3);//i3字符串转换异常:NumberFormatException:
}
}
关于java8种基本数据类型自动装箱的认识2
最新推荐文章于 2024-07-08 14:58:49 发布