Kotlin Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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") } |
Output:
1 2 3 4 5 6 7 |
number = 80 number = 84 number = 80 number = 20 number = 0 |
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 ).