Which of the following Kotlin number literals is syntactically correct?
easy📝 Syntax Q3 of 15
Kotlin - Data Types
Which of the following Kotlin number literals is syntactically correct?
Aval num = 1__000
Bval num = 0b1010_1010
Cval num = 0x_1A
Dval num = 0b2_010
Step-by-Step Solution
Solution:
Step 1: Understand binary literal rules in Kotlin
Binary literals start with 0b and contain only 0 or 1 digits, underscores allowed between digits.
Step 2: Check each option for syntax correctness
val num = 0b1010_1010 is valid binary with underscores correctly placed. val num = 0b2_010 contains '2' which is invalid in binary. val num = 0x_1A has underscore immediately after 0x which is invalid. val num = 1__000 has consecutive underscores which is invalid.
Final Answer:
val num = 0b1010_1010 -> Option B
Quick Check:
Valid binary literal syntax = D [OK]
Quick Trick:Binary digits only 0 or 1; underscores between digits only [OK]
Common Mistakes:
MISTAKES
Using digits other than 0 or 1 in binary literals
Placing underscore right after prefix 0b or 0x
Using multiple underscores consecutively
Master "Data Types" in Kotlin
9 interactive learning modes - each teaches the same concept differently