Kotlin Arithmetic Operators
In Kotlin, Arithmetic Operators are used to perform Arithmetic operations like Addition, Subtraction, Multiplication, etc., on given input numbers.
In this tutorial, we shall learn about different Arithmetic Operators in Kotlin, their symbols, and how to use Arithmetic operators in Kotlin program.
Table of Arithmetic Operators
The following table covers Arithmetic Operators in Kotlin.
Operator | Symbol | Example | Description |
---|---|---|---|
Addition | + | x + y | Returns the sum of x and y . |
Subtraction | - | x - y | Returns the subtraction of y from x . |
Multiplication | * | x * y | Returns the product of x and y . |
Division | / | x / y | Returns the quotient in the division of x by y . |
Modulus | % | x % y | Returns the remainder in the division of x by y . |
Increment | ++ | ++x | Returns the value of x incremented by 1. |
Decrement | -- | --x | Returns the value of x decremented by 1. |
Kotlin Program for Arithmetic Operators
In the following program, we take two numbers: x
, and y
; and perform Arithmetic Operations on these numbers.
Kotlin Program
fun main() {
var x = 5
var y = 2
val addValue = x + y
println("x + y = $addValue")
val subValue = x - y
println("x - y = $subValue")
val mulValue = x * y
println("x * y = $mulValue")
val divValue = x / y
println("x / y = $divValue")
val modValue = x % y
println("x % y = $modValue")
val incValue = ++x
println("++x % y = $incValue")
val decValue = --y
println("--y = $decValue")
}
Output
x + y = 7
x - y = 3
x * y = 10
x / y = 2
x % y = 1
++x % y = 6
--y = 1
Arithmetic Operators Tutorials
The following tutorials cover each of the Arithmetic Operators in detail with syntax and examples.