0
What's output of this code ?
class precedence { public static void main(String[] a) { System.out.println(5-3+12/3*2); } }
8 ответов
+ 2
precedence order is %, /,*,+,-
+ 1
Multiplication and division have the same precedence so they will evaluate from left to right.
+ 1
And what about precedence order of %,/,* ?
+ 1
* / % all have the same precedence
+ - have the same precedence
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html
+ 1
Thanks buddy @Ap_star_._
0
5-3+12/3*2 = 10
12/3 = 4
4*2 = 8
5-3 = 2
2+8 = 10
0
For 2*3/6 O/P is 1, why so ? Because in previous case division is given more precedence while multiplication in the latter.
0
Thank you @ChaoticDawg