相关疑难解决方法(0)

为什么这两个乘法运算会得到不同的结果?

为什么我需要添加"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)

java int operation multiplication long-integer

37
推荐指数
2
解决办法
5408
查看次数

将int转换为long

我有一个关于在java中从int转换为long的问题.为什么浮标没有问题:

float f = (float)45.45;//compiles no issue.
float f = 45.45f; //compiles no issue.
Run Code Online (Sandbox Code Playgroud)

但是对于长型,它似乎是一个问题:

    long l = (long)12213213213;
    //with L or l at the end it will work though. 
    long l = (long)12213213213L;
Run Code Online (Sandbox Code Playgroud)

似乎一旦编译器因超出范围的问题而通知错误,它就会在那里阻塞而不检查程序员可能已经计划的任何可能的转换.

你对它有什么看法?为什么有任何特殊原因?

提前致谢.

java int long-integer

3
推荐指数
1
解决办法
181
查看次数

标签 统计

int ×2

java ×2

long-integer ×2

multiplication ×1

operation ×1