int foo = 10.9 + 2112 / 100 % 2 - 2;
Printable View
int foo = 10.9 + 2112 / 100 % 2 - 2;
Please define "not working?"
One issue, which I'm not sure is a problem: You're doing int division. 1/2 will result in 0. 1.0/2 will result in 0.5.
Try changing 2112 to 2112.0. Also, you should use parenthesis -- when do you want the mod operator to act?
Try changing 'int' to 'double'.
Hi, this refers to type casting. You can cast type int to double, but reverse not, because it will lose precision. In some IDE, it will give 'Type mismatch: cannot convert from double to int' tip. If you must cast double to int, you can use the following form:
Now, it will be 22, but not 23 and any others.Code:int i = (int) 22.99;
So, you can change your formula to:
and the result is 9.Code:int foo = (int) 10.9 + 2112 / 100 % 2 - 2;
For details, you can refer some java beginners books.