java operatorsd 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: Operators in java

// Arithmetic operators in java
public class ArithmeticOperatorDemo
{
   public static void main(String[] args)
   {
      int i = 25;
      int j = 5;
      System.out.println(i + j);
      System.out.println(i - j);
      System.out.println(i * j);
      System.out.println(i / j);
      System.out.println(i % j);
   }
}

Tags:

Java Example