public class inttest01{
public static void main(String[]args){
/*
错误: 不兼容的类型: 从long转换到int可能会有损失
100L是long类型(8字节)int类型(4字节)
在java语言中大容量无法“直接”转换为小容量
int a = 100L;
Systrm.out.println(a);
*/
//强制类型转换(可能损失精度)
long b = 2147483647L;
int c = (int)b; //这个(int)就是强制类型转换符,进行强制类型转换
//编译可以过 运行会损失精度
System.out.println(c);
}
}
基本数据类型int篇2
最新推荐文章于 2024-07-24 17:27:32 发布