1.6 Arithmetic Operators

Java has five arithmetic operators:
+ (addition), - (subtraction), * (multiplication), / (division), % (mod or remainder)

Arithmetic Operators

Expression

Result

+

2 + 3

5

-

48 - 10

38

*

3 * 5

15

/

14 / 3

4
% 11 % 4 3

/**
 *  This program demonstrates
 *  Arithmetic Operator
 */
public class Arithmetic
{
   public static void main(String[] args)
   {
      System.out.println(12 + 88);
      System.out.println(24 - 10);
      System.out.println(3 * 8);
      System.out.println(31 / 5);
      System.out.println(31 % 5);
      System.out.println(5.0 + 2.5);
      System.out.println(6.4 - 5.2);
      System.out.println(2.4 * 1.2);
      System.out.println(5.5 / 2.0);
      System.out.println(5.5 % 2.0);
   }
}

Program Output:

100
14
24
6
1
7.5
1.2
2.88
2.75
1.5