Compare in Scala

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

In Scala, you can compare numbers using the comparison operators like '>', '<', '>=', '<=', '==' and '!='.

Here are some examples:

val a = 10
val b = 20
val c = 10

// Greater than
println(b > a) // true

// Less than
println(a < b) // true

// Greater than or equal to
println(c >= a) // true

// Less than or equal to
println(a <= c) // true

// Equality check
println(a == c) // true

// Inequality check
println(a != b) // true

In the above example, we have three numbers a, b, and c and have compared them using different comparison operators. The output will be true if the comparison is true and false if the comparison is false.