Welcome to the Kotlin Operators Reference! In this comprehensive guide, we'll explore various operators available in Kotlin, their uses, and examples to help you become a proficient Kotlin developer. Let's dive right in!
Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, division, and modulus.
+)Adds two operands together.
val a = 5
val b = 3
val sum = a + b // sum = 8-)Subtracts one operand from another.
val a = 5
val b = 3
val difference = a - b // difference = 2*)Multiplies two operands together.
val a = 5
val b = 3
val product = a * b // product = 15/)Divides one operand by another.
val a = 10
val b = 2
val quotient = a / b // quotient = 5.0%)Returns the remainder of the division operation.
val a = 10
val b = 3
val remainder = a % b // remainder = 1Assignment operators are used to assign a value to a variable.
=)Assigns the right operand to the left operand.
val a = 5Performs an operation and assigns the result back to the variable.
val a = 5
a += 3 // a = 8Comparison operators are used to compare two operands.
==)Checks if two operands are equal.
val a = 5
val b = 5
if (a == b) println("a is equal to b")!=)Checks if two operands are not equal.
val a = 5
val b = 6
if (a != b) println("a is not equal to b")>)Checks if the left operand is greater than the right operand.
val a = 7
val b = 5
if (a > b) println("a is greater than b")<)Checks if the left operand is less than the right operand.
val a = 3
val b = 5
if (a < b) println("a is less than b")>=)Checks if the left operand is greater than or equal to the right operand.
val a = 7
val b = 5
if (a >= b) println("a is greater than or equal to b")<=)Checks if the left operand is less than or equal to the right operand.
val a = 3
val b = 5
if (a <= b) println("a is less than or equal to b")Which operator is used to perform division in Kotlin?
Hope you enjoyed learning about Kotlin operators! In the next lesson, we'll dive deeper into control flow structures like loops and conditional statements. Until then, happy coding! 🚀