This site requires JavaScript, please enable it in your browser!
Greenfoot back
Tritos
Tritos wrote ...

2016/12/2

weird calculation

Tritos Tritos

2016/12/2

#
hey I am currently having a simple problem with deviding... If I put in this as a simple code in the act method
double j = 500/1400;
 System.out.println(j);
It just says 0.0 in the console. But it should say something like 0.357... Thanks for the help Tritos
Super_Hippo Super_Hippo

2016/12/3

#
I think that happens because 500 and 1400 are ints, so the result is also an int. To prevent that, you can write 500.0 and 1400.0 and you should get the result of 0.357...
danpost danpost

2016/12/3

#
You could also use 500d and 1400d, which declares them as doubles. You may not need it on the 1400 because the 500 is established as a double before the division operation is executed it (I have not tested that though).
Tritos Tritos

2016/12/3

#
Thank you very much
You need to login to post a reply.