Challenge - 5 Problems
Number Literal Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
Output of Kotlin number literals with underscores
What is the output of this Kotlin code snippet?
Kotlin
fun main() { val number = 1_000_000 println(number) }
Attempts:
2 left
💡 Hint
Underscores in number literals are ignored by the compiler and only improve readability.
✗ Incorrect
In Kotlin, underscores in numeric literals are just for readability and do not affect the actual value. So 1_000_000 is the same as 1000000.
❓ Predict Output
intermediate1:30remaining
Output of Kotlin hexadecimal literal
What will this Kotlin code print?
Kotlin
fun main() { val hexNumber = 0x1A println(hexNumber) }
Attempts:
2 left
💡 Hint
Hexadecimal literals start with 0x and represent base 16 numbers.
✗ Incorrect
0x1A in hexadecimal equals 26 in decimal, so the program prints 26.
❓ Predict Output
advanced2:00remaining
Output of Kotlin binary literal with underscores
What is the output of this Kotlin program?
Kotlin
fun main() { val binaryNumber = 0b1010_1101 println(binaryNumber) }
Attempts:
2 left
💡 Hint
Binary literals start with 0b and represent base 2 numbers. Underscores are ignored.
✗ Incorrect
0b10101101 is binary for decimal 173, so the program prints 173.
❓ Predict Output
advanced2:00remaining
Sum of mixed number literals in Kotlin
What is the output of this Kotlin code?
Kotlin
fun main() { val a = 0xF val b = 0b10_10 val c = 10_4 println(a + b + c) }
Attempts:
2 left
💡 Hint
Convert each literal to decimal before adding: 0xF = 15, 0b10_10 = 10, 10_4 = 104.
✗ Incorrect
0xF is 15 decimal, 0b10_10 is binary 1010 which is 10 decimal, 10_4 is 104 decimal. Sum is 15 + 10 + 104 = 129.
❓ Predict Output
expert2:00remaining
Output of Kotlin code with invalid underscore placement
What error does this Kotlin code produce?
Kotlin
fun main() { val invalidNumber = 0x_1F println(invalidNumber) }
Attempts:
2 left
💡 Hint
Underscores cannot be placed right after the 0x prefix in hexadecimal literals.
✗ Incorrect
Kotlin does not allow underscores immediately after the 0x prefix, so this code causes a syntax error.