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)

Tags

Logical Operators , Kotlin

Similar Programs Chapter Last Updated
Kotlin Continue Kotlin 02-03-2018
Kotlin Break Statement Kotlin 27-01-2018
Kotlin For Loop Kotlin 30-11-2017
Kotlin Do While Loop Kotlin 19-11-2017
Kotlin While Loop Kotlin 19-11-2017
Kotlin When Statement Kotlin 18-11-2017
Kotlin Nested If Kotlin 18-11-2017
Kotlin If Else If Statement Kotlin 22-09-2018
Kotlin If Statement Kotlin 17-11-2017
Kotlin Print And Println Kotlin 22-09-2018
Kotlin Type Conversion Kotlin 17-11-2017
Kotlin Assignment Operators Kotlin 15-11-2017
Kotlin Arithmetic Operators Kotlin 15-11-2017
Kotlin Data Types Kotlin 12-11-2017
Kotlin Variables Example Kotlin 11-11-2017
Kotlin Comments Example Kotlin 11-11-2017
Kotlin Hello World Kotlin 11-11-2017

1