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