Java如何处理整数下溢和溢出?
在此之后,您将如何检查/测试这是否正在发生?
为什么我需要添加"L"字母才能获得正确的长值?另一个价值是什么?
long oneYearWithL = 1000*60*60*24*365L;
long oneYearWithoutL = 1000*60*60*24*365;
System.out.println(oneYearWithL);//gives correct calculation result : 31536000000
System.out.println(oneYearWithoutL)//gives incorrect calculation result: 1471228928
Run Code Online (Sandbox Code Playgroud) 我试图理解为什么这个乘法导致不正确的值:
long max = (60 * 24 * 60 * 60 * 1000);
Run Code Online (Sandbox Code Playgroud)
这应该= 5,184,000,000
但在我的Java程序中它= 889,032,704
知道为什么会这样吗?