Bird
0
0

Given the Kotlin variables:

hard📝 Application Q15 of 15
Kotlin - Data Types
Given the Kotlin variables:
val isSunny = false
val hasUmbrella = true
val isWarm = true

Which expression correctly checks if it is either sunny or warm, and you have an umbrella if not sunny?
AisSunny && isWarm || hasUmbrella
B(isSunny || isWarm) && hasUmbrella
C(isSunny && hasUmbrella) || isWarm
DisSunny || (isWarm && hasUmbrella)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the condition

    We want true if it is sunny OR if it is warm AND you have an umbrella when it is not sunny.
  2. Step 2: Translate condition to logic

    The expression should be: isSunny OR (isWarm AND hasUmbrella). This means if sunny, no umbrella needed; if not sunny, then warm and umbrella required.
  3. Final Answer:

    isSunny || (isWarm && hasUmbrella) -> Option D
  4. Quick Check:

    Use parentheses to group AND inside OR [OK]
Quick Trick: Group AND inside OR with parentheses for correct logic [OK]
Common Mistakes:
MISTAKES
  • Ignoring parentheses changing logic
  • Assuming umbrella needed when sunny
  • Mixing AND and OR without grouping

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes