dimanche 28 décembre 2014

Java Ceil Weirdness


Why does this output 0 instead of 1?



System.out.println((int) (Math.ceil(1/2)));


While this one correct outputs 1



System.out.println((int) (Math.ceil((double) 1/ (double) 2)));


Shouldn't Math.ceil(double) automatically type cast the 1/2 to double?





Aucun commentaire:

Enregistrer un commentaire