Operators (Cont.)


Assignment Operators
Assignment operators are used to assign values to variables:

Operator Example Same as Operator Example Same as
= x = 5 x = 5 += x += 3 x = x + 3
-= x -= 3 x = x - 3 *= x *= 3 x = x * 3
/= x /= 3 x = x / 3 %= x %= 3 x = x % 3
&= x &= 3 x = x & 3 |= x |= 3 x = x | 3
^= x ^= 3 x = x ^ 3 >>= x >> = 3 x = x >> 3
<<= x <<= 3 x = x << 3

TernaryOp.java (ternary operator)

  public class TernaryOp {
    public static void main( String[ ] args ) {     
      String a = "";
      String b = "";
      
      Boolean c = ( a == b ) ? true : false;
      System.out.println( c );
    }
  }
Output:            




      I broke my finger last week. On the other hand, I’m okay.