The following code is giving me a wrong answer and I can't understand why.
int x = 10;
int y = 15;
System.out.println((int)Math.ceil(x/y));
Result:
0
I was expecting a 1 as the answer.
The following code is giving me a wrong answer and I can't understand why.
int x = 10;
int y = 15;
System.out.println((int)Math.ceil(x/y));
Result:
0
I was expecting a 1 as the answer.
Inside the Math.ceil function you passed x / y and the answer of x / y in your case is gonna be 0 cause x and y are both integers and in Java, dividing two integers is going to give an integer result, thus 10 / 15 = 0 without taking the decimal digits. You can try defining x or y as double. Then you will get 10 / 15 = 0.666... and the ceil will return a 1.