0
0
Kotlinprogramming~20 mins

Boolean type and logical operators in Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Boolean Logic Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Kotlin code using logical operators?
Consider the following Kotlin code snippet. What will it print?
Kotlin
fun main() {
    val a = true
    val b = false
    val c = a && !b || b
    println(c)
}
Atrue
Bfalse
CCompilation error
DRuntime exception
Attempts:
2 left
💡 Hint
Remember that !b means 'not b', and && has higher precedence than ||.
Predict Output
intermediate
2:00remaining
What does this Kotlin code print with mixed logical operators?
Analyze the output of this Kotlin program:
Kotlin
fun main() {
    val x = false
    val y = true
    val result = x || y && false
    println(result)
}
Atrue
Bfalse
CCompilation error
DRuntime exception
Attempts:
2 left
💡 Hint
&& has higher precedence than || in Kotlin.
🔧 Debug
advanced
2:00remaining
What error does this Kotlin code raise?
Examine this Kotlin snippet and identify the error it produces when compiled or run:
Kotlin
fun main() {
    val a = true
    val b = false
    val c = a && b ||
    println(c)
}
ANo error, prints false
BTypeError
CUnresolved reference error
DSyntaxError
Attempts:
2 left
💡 Hint
Look carefully at the expression assigned to c.
Predict Output
advanced
2:00remaining
What is the output of this Kotlin code using logical negation and equality?
What will this Kotlin program print?
Kotlin
fun main() {
    val a = true
    val b = false
    val c = !(a == b) && (a || b)
    println(c)
}
ACompilation error
Bfalse
Ctrue
DRuntime exception
Attempts:
2 left
💡 Hint
Evaluate the equality first, then apply negation and logical operators.
🧠 Conceptual
expert
3:00remaining
How many items are in the resulting list after filtering with logical operators?
Given this Kotlin code, how many elements does the list 'filtered' contain?
Kotlin
fun main() {
    val numbers = listOf(1, 2, 3, 4, 5, 6)
    val filtered = numbers.filter { it % 2 == 0 && it > 3 || it == 1 }
    println(filtered.size)
}
A4
B3
C2
D5
Attempts:
2 left
💡 Hint
Remember that && has higher precedence than || in Kotlin filter conditions.