Challenge - 5 Problems
Logical Operator Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Kotlin code using logical AND (&&)?
Consider the following Kotlin code snippet. What will it print?
Kotlin
fun main() { val a = true val b = false println(a && b) }
Attempts:
2 left
💡 Hint
Remember that && returns true only if both sides are true.
✗ Incorrect
The && operator returns true only if both operands are true. Here, a is true but b is false, so the result is false.
❓ Predict Output
intermediate2:00remaining
What does this Kotlin code print using logical OR (||)?
Look at this Kotlin code. What will be printed?
Kotlin
fun main() { val x = false val y = false println(x || y) }
Attempts:
2 left
💡 Hint
|| returns true if at least one operand is true.
✗ Incorrect
Both x and y are false, so x || y is false.
❓ Predict Output
advanced2:00remaining
What is the output of this Kotlin code using NOT (!) operator?
What will this Kotlin program print?
Kotlin
fun main() { val flag = true println(!flag) }
Attempts:
2 left
💡 Hint
The ! operator reverses the boolean value.
✗ Incorrect
The ! operator negates true to false.
❓ Predict Output
advanced2:00remaining
What is the output of this Kotlin code combining &&, ||, and !?
Analyze this Kotlin code and determine what it prints.
Kotlin
fun main() { val a = true val b = false val c = true println((a && !b) || (b && c)) }
Attempts:
2 left
💡 Hint
Evaluate !b first, then &&, then ||.
✗ Incorrect
!b is true because b is false. So a && !b is true && true = true. b && c is false && true = false. true || false = true.
🧠 Conceptual
expert3:00remaining
Which Kotlin expression evaluates to false?
Given these variables: val p = false, val q = true, which expression evaluates to false?
Attempts:
2 left
💡 Hint
Evaluate each expression step by step using operator precedence.
✗ Incorrect
Option A is !p && !q = true && false = false. All others evaluate to true.