0
0
Kotlinprogramming~20 mins

Int, Long, Float, Double number types in Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Number Types 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 mixed number types?

Look at this Kotlin code snippet. What will it print?

Kotlin
fun main() {
    val a: Int = 10
    val b: Long = 20L
    val c: Float = 5.5f
    val d: Double = 3.0
    println(a + b + c + d)
}
A38
BCompilation error
C38.5f
D38.5
Attempts:
2 left
💡 Hint

Remember Kotlin automatically converts smaller types to larger types in expressions.

🧠 Conceptual
intermediate
1:30remaining
Which Kotlin number type has the largest range?

Among Int, Long, Float, and Double, which type can hold the largest range of values?

ADouble
BLong
CFloat
DInt
Attempts:
2 left
💡 Hint

Think about the size and precision of floating point types compared to integer types.

🔧 Debug
advanced
2:00remaining
Why does this Kotlin code cause a compilation error?

Examine this Kotlin code. Why does it not compile?

Kotlin
fun main() {
    val x: Int = 10
    val y: Long = 20L
    val z = x + y
    println(z)
}
ALong literals must end with uppercase L only
BVariable z is not declared with a type
CCannot add Int and Long directly without explicit conversion
DInt cannot be assigned to Long
Attempts:
2 left
💡 Hint

Check how Kotlin handles arithmetic between different integer types.

Predict Output
advanced
1:30remaining
What is the output of this Kotlin code with floating point precision?

What will this Kotlin program print?

Kotlin
fun main() {
    val a: Float = 0.1f
    val b: Double = 0.1
    println(a == b)
}
Atrue
BRuntime exception
CCompilation error
Dfalse
Attempts:
2 left
💡 Hint

Consider how floating point numbers are stored and compared.

Predict Output
expert
2:30remaining
What is the value of variable result after running this Kotlin code?

After running this code, what is the value of result?

Kotlin
fun main() {
    val x: Int = 100000
    val y: Int = 100000
    val result: Long = x.toLong() * y.toLong()
    println(result)
}
A10000000000
B-727379968
CCompilation error
D1000000000
Attempts:
2 left
💡 Hint

Think about integer overflow and type conversion before multiplication.