Reading Time: < 1 minuteWe have following types of Arithmetic operators in Kotlin.
Operators | Expression | Equivalent To | Description | |
Addition | + | a + b | a.plus(b) | Used for Addition |
Subtraction | – | a – b | a.minus(b) | Used for Subtraction |
Multiplication | * | a * b | a.times(b) | Used for multiplication |
Division | / | a / b | a.div(b) | Used for division |
Modulo | % | a % b | a.mod(b) | Used to get remainder of the division |
These operations are binary, wich means they operate with two operands.
Addition
The following code declares two integer variables and prints their sum using the + (addition) operators
Division
The division (/) operator results in an integer, removing any remainder.
Modulo
To get the remainder of the division, use the % (modulo) operator.
The modulo operator cannot be applied to floating-point numbers.
However the division operator works with floating-point values and results in a floating-point result.
Follow and like us:
Click to rate this post!
[Total: 1 Average: 2]