operators in java example program

Example 1: 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);
   }
}

Example 2: Operators in java

// java unary increment (++) operator
public class JavaUnaryOperator
{
   public static void main(String[] args)
   {
      int a = 23;
      // 23 gets printed and increment to 24
      System.out.println("Java post-increment = " + a++);
      // a value was 24, incremented to 25
      System.out.println("Java pre-increment = " + ++a);
   }
}

Tags:

Java Example