Bird
0
0

You need to store the total number of stars in a galaxy, estimated to be around 1.4 billion. Which Kotlin numeric type is most appropriate and why?

medium📝 Application Q8 of 15
Kotlin - Data Types
You need to store the total number of stars in a galaxy, estimated to be around 1.4 billion. Which Kotlin numeric type is most appropriate and why?
ALong, because it can hold large whole numbers beyond Int's limit
BInt, because it can store any whole number up to 2 billion
CFloat, because it can store large decimal numbers efficiently
DDouble, because it is the default type for decimal numbers
Step-by-Step Solution
Solution:
  1. Step 1: Understand the number size

    The number 1.4 billion (1,400,000,000) exceeds the maximum value of Int (2,147,483,647).
  2. Step 2: Choose a type that can hold large whole numbers

    Long can store values up to 9,223,372,036,854,775,807, which is sufficient.
  3. Final Answer:

    Long -> Option A
  4. Quick Check:

    1.4 billion < Long max value [OK]
Quick Trick: Use Long for whole numbers larger than Int max [OK]
Common Mistakes:
MISTAKES
  • Choosing Int without considering its max limit
  • Using Float or Double for whole numbers unnecessarily
  • Assuming Int can hold all large numbers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes