Evaluation Order of Java Operand

Evaluation Order of Java Operand 

Before applying any operator, all the Operands should be evaluated from left to right.

package com.javaoperators;
public class OperatorExample {

public static void main(String[] args) {

    int total=m1(1) + m1(2) * m1(3) + m1(4) / m1(5) + m1(6);
    System.out.println("Total:"+total);
}

public static int m1(int i) {
    System.out.println("value:"+i);
    return i;
}
}

Output

value:1
value:2
value:3
value:4
value:5
value:6
Total:13

The Author

Narayanaswamy

Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in IT industry more than 7 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting and Website Development. I am a self learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.

Leave a Reply