JAVA学习笔记02-integer

package day01;

public class IntegerDemo {
    public static void main(String[] args) {
        // int 占用 4字节
        int a = 300;
        // int b = -2147483648;
        // int c = 2147483647;
        // int d = 2147483648; 编译错误,超过了当前变量类型可容纳的范围

        int c = 5;
        int d = 2;
        System.out.println(c/d);

        int e = 2147483647; // int最大值
        int f = e + 1;
        System.out.println(f); // 溢出的结果

        // long 占用8字节
        /**
         * 最大值 + 1 ---------- (-2147483648)
         * 最大值 + 1 + 1 ------ (-2147483647)
         * 最大值 + 1 + 2-*/

        long a1 = 1000000000L;
        long b1 = 1000000000 * 2 * 10L;
        System.out.println(b1);

        // long c1 = 1000000000 * 3 * 10L; // 1000000000 * 3 int计算时溢出了
        long c1 = 1000000000L * 3 * 10;
        System.out.println(c1);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值