Kotlin Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
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) } |
Output:
1 2 3 4 5 6 |
false Logical NOT Operator : true true Logical NOT Operator : false |
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)