Compare in Kotlin

Find this useful? Support us: Star on GitHub 6
Category: String | Language: Kotlin

In Kotlin, you can compare numbers using comparison operators >, <, >=, <=, ==, and !=.

Here are some examples:

val num1 = 5
val num2 = 10

// greater than
println(num2 > num1) // output: true

// less than
println(num1 < num2) // output: true

// greater than or equal to
println(num2 >= 10) // output: true

// less than or equal to
println(num1 <= 5) // output: true

// equal to
println(num1 == 5) // output: true

// not equal to
println(num1 != num2) // output: true

In the above example, we have two variables num1 and num2 and we have used all the comparison operators to compare them with different values. We used the println() function to print the output of each comparison.