Integer.parseInt 能转换的最大值是 2147483647

Integer.parseInt 能转换的最大值是 2147483647

测试数据:
String fee1 = “2147483647”;
String fee2 = “2147483648”

public class test {
    public static void main(String[] args) {


        String fee1 =  "2147483647";
        String fee2 =  "2147483648";

        try{
            int fee_x2 = Integer.parseInt(fee2);
            System.out.println(fee_x2);
            System.out.println(getType(fee_x2));
        }catch(Exception e){
            System.out.println("fee2超出范围!");
        }

        try{
            int fee_x = Integer.parseInt(fee1);
            System.out.println(fee_x+"fee1正常");
            System.out.println(getType(fee_x));
        }catch(Exception e){
            System.out.println("fee1超出范围!");
        }

    }
    public static String getType(Object o){
        return o.getClass().toString();
    }
}

结果 :

fee2超出范围!
2147483647fee1正常
class java.lang.Integer

Integer.parseInt 能转换的最大值是 2147483647_第1张图片

你可能感兴趣的:(Java开发问题,java,动态规划,链表)