Calculations

Name Operator Examples Result
Addition + 1 + 3 4
'Awe' + 'some' Awesome
3.5 + 2.4 5.9
Subtraction - 5 - 3 2
2 - 2 0
3 - 5 -2
Multiplication * 2 * 2 4
3 * 5 15
3 * 0 0
Division / 10 / 2 5
0 / 3 0
5 / 0 Exception - cannot divide by 0.
Remainder Of Division % 10 % 2 0
4 % 3 1
17 % 6 5

Explanation for Remainder Of Division

division-remainder

Let's start with a program that prints rectangle's area by knowing it's width and height.

Output:

Explanation

  • At line 5 width and height are multiplied (via * operator).

Let's demonstrate the rest of the operators:

Output: