Assignment & Operator part 6

Assignment & Operator part 6

                                         Java Operator Precedence

    1 unary Operator([],x++,x--,++x,--x,~,!,new,<type>) 
   2 Arithmetic Operator(*,/,%,+,-)
   3 Shift Operators(>> ,>>>,<<)
   4 Comprasion Operators(<,<=,>,>=,instanceof)
   5 Equality Operators(==,!=)
   6 Bitwise Operator(^,&,|)
   7 Short Circuit Operators(&&,||)
   8 Conditional Operators(?:)
   9 Assignment Operators(=,+=,-=,*=,/=,............)

evaluation order of java operands -:In java we have only operator precedence but not operand precedence before applying any operator all operands will be evaluated from left to right.

Example-:
/*
class Test {
public static int m1(int x){
   System.out.println(x);
   return x;
}
public static void main(String... args){
   System.out.print(m1(1)+m1(2)*m1(3)/m1(4)+m1(5)*m1(6));
}
}
output is-: 1
                  2
                  3
                  4
                  5
                  6
                  32 
evalution    (1+2*3/4+5*6)
                  (1+6/4+5*6)
                  (1+1+5*6)
                  (1+1+30)
                   (2+30)
                
*/
Previous Post Next Post

Most Recent