0
Can anyone explain why I am getting output as 12 ?
public class Program { public static void main(String[] args) { int var1=5; int var2=6; int var3; var3=++var2*var1/var2+var2; System.out.println(var3); } }
3 ответов
+ 1
++Var2=7*var1=5/var1=7
=7*5/7=5
Now var2=7+5=12
You will get the answer 2 if you enclose each operation in common brackets or parenthesis
+ 1
According to BODMAS we should do var1/var2?
+ 1
Var3=++6*5/6+6
Var3=7*5/7+7
Var3=35/7+7
Var3=5+7
Var3=12