Int is a number type in Kotlin that stores whole numbers without decimals. It uses 32 bits and can hold values from -2,147,483,648 to 2,147,483,647.
Click to reveal answer
beginner
How is Long different from Int in Kotlin?
Long is a number type that stores bigger whole numbers than Int. It uses 64 bits and can hold values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
Click to reveal answer
beginner
What does the Float type represent in Kotlin?
Float is a number type for decimal numbers (numbers with fractions). It uses 32 bits and is less precise than Double. You write a Float number with an 'f' or 'F' at the end, like 3.14f.
Click to reveal answer
beginner
Explain the Double type in Kotlin.
Double is a number type for decimal numbers with more precision than Float. It uses 64 bits and is the default type for decimal numbers in Kotlin.
Click to reveal answer
beginner
How do you write a Long and a Float literal in Kotlin?
To write a Long number, add 'L' or 'l' at the end, like 123L. To write a Float number, add 'f' or 'F' at the end, like 3.14f.
Click to reveal answer
Which Kotlin type would you use to store the number 5000000000?
ALong
BInt
CFloat
DDouble
✗ Incorrect
5000000000 is too big for Int, so Long is the correct type.
What suffix do you add to a number to make it a Float in Kotlin?
AL
Bf
CF64
Dd
✗ Incorrect
You add 'f' to make a number a Float, like 2.5f.
Which type is the default for decimal numbers in Kotlin?
AInt
BLong
CFloat
DDouble
✗ Incorrect
Double is the default decimal type in Kotlin.
What is the size in bits of the Int type in Kotlin?
A64 bits
B16 bits
C32 bits
D128 bits
✗ Incorrect
Int uses 32 bits to store whole numbers.
Which type can store the largest whole number?
ALong
BFloat
CInt
DDouble
✗ Incorrect
Long can store larger whole numbers than Int.
Describe the differences between Int, Long, Float, and Double in Kotlin.
Think about size, precision, and whether the number has decimals.
You got /4 concepts.
How do you write literals for Long and Float types in Kotlin? Give examples.
Remember the suffix letters for each type.
You got /2 concepts.
Practice
(1/5)
1. Which Kotlin number type should you use to store a whole number like 42?
easy
A. Float
B. Double
C. Int
D. Long
Solution
Step 1: Understand the number type categories
Int is used for normal whole numbers without decimals.
Step 2: Match the number 42 to the type
42 is a whole number and fits in Int range.
Final Answer:
Int -> Option C
Quick Check:
Whole number 42 = Int [OK]
Hint: Whole numbers without decimals use Int by default [OK]
Common Mistakes:
Choosing Float or Double for whole numbers
Using Long unnecessarily for small numbers
2. Which of the following is the correct way to declare a Float variable with value 3.14 in Kotlin?
easy
A. val pi: Float = 3.14
B. val pi: Float = 3.14Ff
C. val pi: Float = 3.14d
D. val pi: Float = 3.14f
Solution
Step 1: Recall Kotlin Float literal syntax
Float literals require an 'f' or 'F' suffix to distinguish from Double.
Step 2: Check each option
val pi: Float = 3.14f uses '3.14f' which is correct. val pi: Float = 3.14 misses the suffix. val pi: Float = 3.14Ff has invalid suffix 'Ff'. val pi: Float = 3.14d uses 'd' which is for Double.
Final Answer:
val pi: Float = 3.14f -> Option D
Quick Check:
Float literals end with 'f' [OK]
Hint: Add 'f' suffix to decimal for Float type [OK]
Common Mistakes:
Omitting 'f' suffix for Float literals
Using 'd' suffix which is for Double
Using invalid suffixes like 'Ff'
3. What will be the output of this Kotlin code?
val a: Int = 100000 val b: Long = 10000000000L val c: Float = 3.14f val d: Double = 3.1415926535 println("$a $b $c $d")
medium
A. 100000 10000000000 3.1400001 3.1415926535
B. 100000 10000000000 3.14 3.1415926535
C. 100000 10000000000 3.14f 3.1415926535
D. 100000 10000000000 3.14 3.1415927
Solution
Step 1: Understand variable types and precision
a is Int (100000), b is Long (10000000000L), c is Float (3.14f), d is Double (3.1415926535).
Step 2: Check printed values and precision
Float prints as 3.1400001 due to precision limits, Double prints full precision (3.1415926535). So output matches 100000 10000000000 3.1400001 3.1415926535.
Final Answer:
100000 10000000000 3.1400001 3.1415926535 -> Option A
Quick Check:
Float prints with slight precision difference [OK]
Hint: Float prints decimals with limited precision [OK]
Common Mistakes:
Thinking Float prints exactly 3.14
Confusing Float and Double precision
Misreading Long large number formatting
4. Identify the error in this Kotlin code snippet:
val bigNumber: Long = 12345678901234567890 val smallNumber: Int = 2147483648
medium
A. Both numbers are too large for their types
B. Only bigNumber is too large for Long
C. No errors, code is correct
D. Only smallNumber is too large for Int
Solution
Step 1: Check Long value range
Long can hold values up to 9,223,372,036,854,775,807. The bigNumber literal exceeds this, so it causes an error.
Step 2: Check Int value range
Int max is 2,147,483,647. The smallNumber is 2,147,483,648 which is 1 more than max, so it causes an error.
Step 3: Analyze the code
Both literals are too large for their types, causing compile errors.
Final Answer:
Both numbers are too large for their types -> Option A
Quick Check:
Int max 2147483647, Long max 9223372036854775807; both exceeded [OK]
Hint: Check max values: Int max 2,147,483,647; Long max 9,223,372,036,854,775,807 [OK]
Common Mistakes:
Ignoring suffix 'L' for Long literals
Assuming Long can hold any big number
Not checking Int max value
5. You want to store the population of a country which is about 1.4 billion people. Which Kotlin type is best and why?
Options: A) Long because it can store very large whole numbers B) Int because it stores whole numbers C) Float because it stores decimal numbers D) Double because it stores decimal numbers with more precision
hard
A. Int because it stores whole numbers
B. Long because it can store very large whole numbers
C. Float because it stores decimal numbers
D. Double because it stores decimal numbers with more precision
Solution
Step 1: Understand the population size and type limits
Population is about 1.4 billion (1,400,000,000). Int max is 2,147,483,647, so Int can hold it.
Step 2: Consider best practice for large numbers
Though Int can hold 1.4 billion, Long is safer for very large whole numbers and future growth.
Step 3: Decide on the best type
Long is best because it can store very large whole numbers beyond Int range.
Final Answer:
Long because it can store very large whole numbers -> Option B
Quick Check:
Long preferred for large integers like population [OK]
Hint: Use Long for very large whole numbers like population [OK]
Common Mistakes:
Choosing Int without considering future growth
Using Float or Double for whole numbers unnecessarily
Ignoring future growth beyond Int range
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.