javacodex.com
Java Examples
Java Examples
memu home questions

Arithmetic Operators

The following java example demonstrates the java programming arithmetic operators:
  +  additive operator    
  -  subtraction operator
  *  multiplication operator
  /  division operator
  %  remainder operator

Source: (ArithmeticOperators.java)

public class ArithmeticOperators {
   public static void main(String[] args) {
      int x = 9;
      System.out.println("x = " + x );
      System.out.println("x + 1 = " + (x + 1));
      System.out.println("x - 1 = " + (x - 1));
      System.out.println("x * 2 = " + (x * 2));
      System.out.println("x / 3 = " + (x / 3));
      System.out.println("x % 2 = " + (x % 2));
   }
}
 

Output:

# java ArithmeticOperators 
x = 9
x + 1 = 10
x - 1 = 8
x * 2 = 18
x / 3 = 3
x % 2 = 1

Contact: javacodex@yahoo.com