Why negative value comes for long after multiplication? [duplicate]

天大地大妈咪最大 提交于 2020-01-11 14:26:33

问题


Why this code in java gives negative value?

    long ttt = (60 * 60 * 1000 * 24 * 26);
    System.out.println(ttt);

Result which comes as on eclipse console -2134967296?

Anything silly I am doing, may be it crossed int range I guess?


回答1:


Because 60 * 60 * 1000 * 24 * 25 overflows in the int range.

Make one of them a long so that promotion occurs

60L * 60 * 1000 * 24 * 25


来源:https://stackoverflow.com/questions/24174088/why-negative-value-comes-for-long-after-multiplication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!