+ 1

Why this java code result is 0

int c = (300-315); float g = c/300; System.out.println("percentage of salary changes is : " + g);

31st Mar 2018, 10:12 AM
Salim13i
Salim13i - avatar
1 Odpowiedź
+ 9
Both c and 300 are integer, so their quotient is also integer. You may use any of the following ways to convert the quotient into float or double: 1. float g = c/300.0f; 2. double g = c/300.0; 3. double g = (double) c/300;
31st Mar 2018, 10:33 AM
Shamima Yasmin
Shamima Yasmin - avatar