Program to demonstrate how Operator Precedence works in Java
Output of the program :
public class PrecedenceTest {
public static void main(String[] args) {
int a = 1, b = 2, c = 3;
int x = a + b - 2/2 + c;
int y = a + (b - 2)/(2 + c);
int z = (a + b) - 2/(2 + c);
System.out.println("x = " + x);
System.out.println("y = " + y);
System.out.println("z = " + z);
}
}
Output of the program :
