Причина в правилах продвижения java. в выражении (i/100) оба являются целыми, поэтому результат равен целым числам. 99/100 является o.99, когда преобразуется в целое становится 0.
Согласно спецификации языка Java (Numberic Promotion 5.6
Numeric promotion (§5.6) brings the operands of a numeric operator to a common type so that an operation can be performed.
When an operator applies binary numeric promotion to a pair of operands, each of which must denote a value that is convertible to a numeric type, the following rules apply, in order:
1. If any operand is of a reference type, it is subjected to unboxing conversion
(§5.1.8).
2. Widening primitive conversion (§5.1.2) is applied to convert either or both
operands as specified by the following rules:
• If either operand is of type double, the other is converted to double.
• Otherwise, if either operand is of type float, the other is converted to float.
• Otherwise, if either operand is of type long, the other is converted to long.
• Otherwise, both operands are converted to type int.
Нет, вы не можете. Вам нужно явно отличать от double to float. (i/100.0) вернет двойное значение. –
@SagarGandhi: - Спасибо, что указали это. –