0
0
Kotlinprogramming~20 mins

Char type and Unicode behavior in Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Unicode Char Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
}
A67
BC
CError: Operator '+' cannot be applied to 'Char' and 'Int'
DB
Attempts:
2 left
💡 Hint
Remember that Char plus Int results in an Int in Kotlin.
Predict Output
intermediate
2: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)
}
A937
BOmega
CError: 'code' property not found
D0x03A9
Attempts:
2 left
💡 Hint
The 'code' property returns the Unicode code point as an Int.
Predict Output
advanced
2: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)
}
A
false
false
B
false
true
C
true
true
D
true
false
Attempts:
2 left
💡 Hint
Check if 'e' and 'z' fall within the range from 'a' to 'u'.
Predict Output
advanced
2: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)
}
APrints 1
BPrints 49
CType mismatch: inferred type is Char but Int was expected
DNo output, infinite loop
Attempts:
2 left
💡 Hint
Kotlin does not allow implicit conversion from Char to Int.
🧠 Conceptual
expert
3: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)
}
A1
B2
C0
DError at runtime
Attempts:
2 left
💡 Hint
Kotlin strings use UTF-16 encoding; surrogate pairs count as two chars.