Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

How Operator Precedence works in Java ?

Program to demonstrate how Operator Precedence works in Java

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 :



 
© 2021 Learn Java by Examples Template by Hubberspot