Kotlin Division Assignment Operator
Kotlin Division Assignment Operator divides the left operand by right operand, and assigns the quotient to the left operand.
Syntax
The syntax to use Division Assignment operator is
x /= value
where
x
is the variable name/=
is the symbol used for Division Assignment operatorvalue
is the value that we would like to divide the variablex
with
The above expression is equivalent to
x = x / value
Examples
Divide the value in x by 5
In the following program, we take a variable: x
with an initial value of 21
. Using Division Assignment operator, we divide the value in x
by 5
.
Kotlin Program
fun main() {
var x = 21
x /= 5
println(x)
}
Output
4
Explanation
x /= 5
x = x / 5
x = 21 / 5
x = 4