operators in java programming code example

Example 1: Operators in java

// java assignment operator with examples
public class AssignmentOperatorDemo
{
   public static void main(String[] args)
   {
      int numOne = 60;
      int numTwo = 30;
      numTwo += numOne;
      System.out.println("(+=) : " + numTwo);
      numTwo -= numOne;
      System.out.println("(-=) : " + numTwo);
      numTwo *= numOne;
      System.out.println("(*=) : " + numTwo);
      numTwo /= numOne;
      System.out.println("(/=) : " + numTwo);
      numTwo %= numOne;
      System.out.println("(%=) : " + numTwo);
   }
}

Example 2: |= java operation

foo = 32;   // 32 =      0b00100000
bar = 9;    //  9 =      0b00001001
baz = 10;   // 10 =      0b00001010
foo |= bar; // 32 | 9  = 0b00101001 = 41
            // now foo = 41
foo |= baz; // 41 | 10 = 0b00101011 = 43
            // now foo = 43

Tags:

Java Example