Namaste everyone,
Why does “int x = 200/0;”
gives an error but
int x = 200/20*0; gives the value as 0.?
Thanks.
Namaste everyone,
Why does “int x = 200/0;”
gives an error but
int x = 200/20*0; gives the value as 0.?
Thanks.
Because 200/20*0
is (200/20)*0
, not 200/(20*0)
.
Cheers
— mnse
Hello @prathmesh,
A search for:
operator precedence Java
will reveal the answer to your question.
The Oracle Java documentation:
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html
Parentheses discussed here:
When writing compound expressions, be explicit and indicate with parentheses which operators should be evaluated first. This practice makes code easier to read and to maintain.
:)
Thanks for the links