Kotlin Assignment Operators
Chapter:
Kotlin
Last Updated:
15-11-2017 19:07:23 UTC
Program:
/* ............... START ............... */
fun main(args: Array<String>) {
var number = 20
number *= 4
println("number = $number")
number += 4
println("number = $number")
number -= 4
println("number = $number")
number /= 4
println("number = $number")
number %= 4
println("number = $number")
}
/* ............... END ............... */
Output
number = 80
number = 84
number = 80
number = 20
number = 0
Notes:
-
In Kotlin assignment operators assigns the value on its right to the operand on its left.
- Operator ( = ) : Simple assignment operator. Assigns values from right side operands to left side operand ( a = b ).
- Operator ( += ) : Add AND assignment operator. It adds right operand to the left operand and assign the result to left operand ( a +=b ).
- Operator ( -= ) : Subtract AND assignment operator. It subtracts right operand from the left operand and assign the result to left operand ( a -= b ).
- Operator ( /= ) : Divide AND assignment operator. It divides left operand with the right operand and assign the result to left operand ( a /= b ).
- Operator ( %= ) : Modulus AND assignment operator. It takes modulus using two operands and assign the result to left operand ( a %= b ).