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 ).
Similar Programs Chapter Last Updated
Kotlin Continue Kotlin 02-03-2018
Kotlin Break Statement Kotlin 27-01-2018
Kotlin For Loop Kotlin 30-11-2017
Kotlin Do While Loop Kotlin 19-11-2017
Kotlin While Loop Kotlin 19-11-2017
Kotlin When Statement Kotlin 18-11-2017
Kotlin Nested If Kotlin 18-11-2017
Kotlin If Else If Statement Kotlin 22-09-2018
Kotlin If Statement Kotlin 17-11-2017
Kotlin Print And Println Kotlin 22-09-2018
Kotlin Type Conversion Kotlin 17-11-2017
Kotlin Logical Operators Kotlin 17-11-2017
Kotlin Arithmetic Operators Kotlin 15-11-2017
Kotlin Data Types Kotlin 12-11-2017
Kotlin Variables Example Kotlin 11-11-2017
Kotlin Comments Example Kotlin 11-11-2017
Kotlin Hello World Kotlin 11-11-2017

1