+ 19

Char arithmetic

Can anyone please explain to me what's happening here😨 public class Program { public static void main(String[] args) { char ch = '0'; ch *= 1.1; System.out.println(ch); } } Output: 4

24th Jul 2017, 9:51 AM
Corne
Corne - avatar
2 ответов
+ 16
The ASCII value of '0' is 48. 48 * 1.1 = 52.8 52.8 floored (52) and reinterpreted to char is is '4'.
24th Jul 2017, 10:00 AM
Hatsy Rei
Hatsy Rei - avatar
+ 18
@Hatsy Rei Thanks mate
24th Jul 2017, 10:15 AM
Corne
Corne - avatar