Bird
0
0

Find the error in this Kotlin code snippet:

medium📝 Debug Q14 of 15
Kotlin - Operators and Expressions
Find the error in this Kotlin code snippet:
val x = true
val y = false
if x && y {
    println("Both true")
}
AMissing parentheses around condition in if statement
BUsing && instead of ||
CIncorrect println syntax
DVariables x and y not declared
Step-by-Step Solution
Solution:
  1. Step 1: Check if statement syntax

    Kotlin requires parentheses around the condition in if statements.
  2. Step 2: Identify the error

    The code uses if x && y without parentheses, which causes a syntax error.
  3. Final Answer:

    Missing parentheses around condition in if statement -> Option A
  4. Quick Check:

    if condition needs parentheses [OK]
Quick Trick: Always put () around if conditions [OK]
Common Mistakes:
MISTAKES
  • Omitting parentheses in if
  • Confusing && with ||
  • Wrong println usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes