Bird
0
0

Given val a = true, val b = false, and val c = true, which expression returns true only if exactly two variables are true?

hard📝 Application Q9 of 15
Kotlin - Data Types
Given val a = true, val b = false, and val c = true, which expression returns true only if exactly two variables are true?
A(a && b && !c) || (a && !b && c) || (!a && b && c)
Ba && b && c
Ca || b || c
D(a && b) || (b && c) || (a && c)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the requirement

    Return true only if exactly two variables are true.
  2. Step 2: Analyze options

    (a && b && !c) || (a && !b && c) || (!a && b && c) checks all combinations where exactly two are true and one is false.
  3. Final Answer:

    (a && b && !c) || (a && !b && c) || (!a && b && c) returns true only if exactly two are true -> Option A
  4. Quick Check:

    Check all two-true combinations explicitly [OK]
Quick Trick: Combine AND and NOT to check exact true counts [OK]
Common Mistakes:
MISTAKES
  • Using OR only returns true if any is true
  • Using AND only returns true if all are true
  • Ignoring the exact count condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes