Math operators in apex
To manipulate numeric data, apex supports math operators. Following are the math operators in apex:
- Addition
Adds two numbers together.
Integer x = 5; Integer y = 3; Integer result = x + y; // result is 8
- Subtraction
Subtracts the second number from the first.
Integer x = 5; Integer y = 3; Integer result = x - y; // result is 2
- Multiplication
Multiplies two numbers.
Integer x = 5; Integer y = 3; Integer result = x * y; // result is 15
- Division
Divides the first number by the second.
Integer x = 6; Integer y = 3; Integer result = x / y; // result is 2
Apart from math operators, apex provides a set of math functions which can be used to perform math operations
The following code snippet shows how to add two numbers in apex.
Loading...
In the above example:
- The variables numb1, numb2 are
Integer
variables. - The variable
sum
store the sum of numb1, numb2.
Try It Yourself
Loading...