Kotlin Logical Operators
Chapter:
Kotlin
Last Updated:
17-11-2017 06:50:36 UTC
Program:
/* ............... START ............... */
fun main(args: Array<String>) {
val a = 30
val b = 10
val c = -4
val Andresult : Boolean
val OrResult : Boolean
Andresult = (a>b) && (a<c)
println(Andresult)
println("Logical NOT Operator : "+!Andresult)
OrResult = (a>b) || (a<c)
println(OrResult)
println("Logical NOT Operator : "+!OrResult)
}
/* ............... END ............... */
Output
false
Logical NOT Operator : true
true
Logical NOT Operator : false
Notes:
-
Kotin Logical operators used with Boolean (logical) values. They return boolean value. However, the && and || operators actually return the value of one of the specified operands.
- Operator (||) - true if either of the Boolean expression is true. (Expression : (a>b)||(a<c))
- Operator (&&) - true if all Boolean expressions are true. (Expression : (a>b)&&(a<c)