除以双,0为结果?

时间:2018-06-10 16:28:40

标签: java

很明显

 int x = 3/4; // x is 0 here

但我不明白为什么以下情况也是如此:

double x = 3/4; // x is also 0 here

通过以下我能够得到我想要的结果:

 double x = (double) 3/4; // x is 0.75 here, but why do i have to cast?

0 个答案:

没有答案