0

Please tell me where i made a mistake?

I want same output for both cases. public class Program { public static void main(String[] args) { int num1 = 4; int num2 = 28; num2/=num1+num2; // num2=(num2/num1)+(num2/num2); System.out.println(num2); } } Here output comes : 0 public class Program { public static void main(String[] args) { int num1 = 4; int num2 = 28; // num2/=num1+num2; num2=(num2/num1)+(num2/num2); System.out.println(num2); } } Output comes : 8

1st Feb 2021, 9:11 AM
Nalayak_
Nalayak_ - avatar
3 Respuestas
+ 5
"num2 /= num1 + num2;" ≡ "num2 = num2 / (num1 + num2);" ≢ "num2 = (num2 / num1) + (num2 / num2);"
1st Feb 2021, 9:16 AM
#0009e7 [get]
#0009e7 [get] - avatar
+ 3
SauravK.__, yes. In my previous comment "≡" means "identical to" and "≢" means "not identical to".
1st Feb 2021, 9:32 AM
#0009e7 [get]
#0009e7 [get] - avatar
+ 1
you want to say: num2/=num1+num2; != (num2/num1 + num2/num2); that's why both cases have different output??
1st Feb 2021, 9:28 AM
Nalayak_
Nalayak_ - avatar