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);

}

}

相关推荐
吃我一窝jio42 分钟前
Python与Go线程模型深度对比
java·开发语言·python
这个昵称不容易1 小时前
SpringBoot 购物推荐网站的设计与实现:120 个 Java 文件、147 个接口、13 张表,附真实运行截图
java·springboot·毕设
文丑颜不良啊1 小时前
LeetCode3041~3060题目解析
java·leetcode
文丑颜不良啊2 小时前
LeetCode3101~3120题目解析
java·leetcode
Resean02233 小时前
SpringMVC 6+源码分析(十一)视图渲染与异步请求(收尾篇)
java·spring·springmvc
靠沿3 小时前
MySQL数据库进阶——存储过程和触发器
java·数据库·mysql
小七在进步4 小时前
string的实现(1)
c++·笔记·visual studio
码少女4 小时前
MySQL--库与表的增删改查基础
java·数据库·mysql
瑞克-桑切斯6 小时前
Kubernetes 1.28 保姆级新手学习教程
运维·学习·docker·云原生·容器·kubernetes
Flynt6 小时前
掘金热文说 Spring Boot 4.1 默认开虚拟线程,我实测后发现了更狠的坑
java·spring boot·性能优化