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

}

}

相关推荐
侠客行03174 小时前
Mybatis连接池实现及池化模式
java·mybatis·源码阅读
蛇皮划水怪4 小时前
深入浅出LangChain4J
java·langchain·llm
羊群智妍5 小时前
2026 AI搜索流量密码:免费GEO监测工具,优化效果看得见
笔记·百度·微信·facebook·新浪微博
老毛肚6 小时前
MyBatis体系结构与工作原理 上篇
java·mybatis
阿蒙Amon6 小时前
TypeScript学习-第10章:模块与命名空间
学习·ubuntu·typescript
AI绘画哇哒哒6 小时前
【干货收藏】深度解析AI Agent框架:设计原理+主流选型+项目实操,一站式学习指南
人工智能·学习·ai·程序员·大模型·产品经理·转行
风流倜傥唐伯虎6 小时前
Spring Boot Jar包生产级启停脚本
java·运维·spring boot
Yvonne爱编码6 小时前
JAVA数据结构 DAY6-栈和队列
java·开发语言·数据结构·python
Re.不晚6 小时前
JAVA进阶之路——无奖问答挑战1
java·开发语言
你这个代码我看不懂6 小时前
@ConditionalOnProperty不直接使用松绑定规则
java·开发语言