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

}

}

相关推荐
NE_STOP11 小时前
MyBatis-配置文件解读及MyBatis为何不用编写Mapper接口的实现类
java
后端AI实验室16 小时前
用AI写代码,我差点把漏洞发上线:血泪总结的10个教训
java·ai
程序员清风18 小时前
小红书二面:Spring Boot的单例模式是如何实现的?
java·后端·面试
belhomme18 小时前
(面试题)Redis实现 IP 维度滑动窗口限流实践
java·面试
Be_Better18 小时前
学会与虚拟机对话---ASM
java
开源之眼21 小时前
《github star 加星 Taimili.com 艾米莉 》为什么Java里面,Service 层不直接返回 Result 对象?
java·后端·github
Maori3161 天前
放弃 SDKMAN!在 Garuda Linux + Fish 环境下的优雅 Java 管理指南
java
用户908324602731 天前
Spring AI 1.1.2 + Neo4j:用知识图谱增强 RAG 检索(上篇:图谱构建)
java·spring boot
小王和八蛋1 天前
DecimalFormat 与 BigDecimal
java·后端
齐生11 天前
iOS 知识点 - IAP 是怎样的?
笔记