Challenge - 5 Problems
Unicode Char Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Kotlin code with Char arithmetic?
Consider the following Kotlin code snippet. What will it print?
Kotlin
fun main() { val c: Char = 'A' val result = c + 2 println(result) }
Attempts:
2 left
💡 Hint
Remember that Char plus Int results in an Int in Kotlin.
✗ Incorrect
In Kotlin, adding an Int to a Char results in an Int representing the Unicode code point sum. 'A' has code 65, plus 2 is 67.
❓ Predict Output
intermediate2:00remaining
What does this Kotlin code print when converting Char to Int?
What is the output of this Kotlin program?
Kotlin
fun main() { val ch: Char = '\u03A9' // Greek capital letter Omega println(ch.code) }
Attempts:
2 left
💡 Hint
The 'code' property returns the Unicode code point as an Int.
✗ Incorrect
The Unicode code point for Greek capital letter Omega (Ω) is 937 decimal.
❓ Predict Output
advanced2:00remaining
What is the output of this Kotlin code using Char ranges and contains?
Analyze the code and select the correct output.
Kotlin
fun main() { val vowels = 'a'..'u' println('e' in vowels) println('z' in vowels) }
Attempts:
2 left
💡 Hint
Check if 'e' and 'z' fall within the range from 'a' to 'u'.
✗ Incorrect
The range 'a'..'u' includes letters from 'a' to 'u'. 'e' is inside, 'z' is outside.
❓ Predict Output
advanced2:00remaining
What error does this Kotlin code raise when converting a Char to Int incorrectly?
What error will this code produce?
Kotlin
fun main() { val ch: Char = '1' val num: Int = ch println(num) }
Attempts:
2 left
💡 Hint
Kotlin does not allow implicit conversion from Char to Int.
✗ Incorrect
You cannot assign a Char directly to an Int variable without explicit conversion.
🧠 Conceptual
expert3:00remaining
How many characters are in this Kotlin string containing Unicode surrogate pairs?
Consider this Kotlin code snippet. How many characters does the string contain?
Kotlin
fun main() { val s = "\uD83D\uDE00" // Unicode emoji 😀 represented as surrogate pair println(s.length) }
Attempts:
2 left
💡 Hint
Kotlin strings use UTF-16 encoding; surrogate pairs count as two chars.
✗ Incorrect
The emoji 😀 is represented by two UTF-16 code units (surrogate pair), so length is 2.