Java Evolution Order Of Operands
In JAVA we have only operator precedence but not operand precedence before applying any operator all operands will be evaluated from Left →Right.
example:-
class Test
{
public static void main(String [ ] args)
{
System.out.println(m1(1) + m1(2) * m1(3) / m1(4) + m1(5) * m1(6) );
}
public static int m1(int i)
{
System.out.println( i );
return i;
}
}
Output is : Analysis:
1 1+ 2 * 3 / 4 + 5 * 6
2 1 + 6 / 4 + 5 *6
3 1 + 1 + 5 * 6
4 1 + 1 + 30
5 = 31
6
32
No comments:
Post a Comment
Be the first to comment!
Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.
Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.
Regards,
JavaByChetan
Back To Home