When I run this code it returns 3 (as I expected) however j prints 0. Could someone explain why this happens.
int i, j;
i = 3;
j = i;
j = j/9*6;
System.out.println(i);
System.out.println(j);
When I run this code it returns 3 (as I expected) however j prints 0. Could someone explain why this happens.
int i, j;
i = 3;
j = i;
j = j/9*6;
System.out.println(i);
System.out.println(j);
You are performing integer division, so j/9 will evaluate to 0, then 0*6 == 0.