Bird
0
0

Which of the following Kotlin declarations correctly defines a variable holding a floating-point number?

easy📝 Syntax Q3 of 15
Kotlin - Data Types
Which of the following Kotlin declarations correctly defines a variable holding a floating-point number?
Aval pi: Float = 3.14f
Bval pi: float = 3.14
Cval pi = 3.14d
Dval pi: Double = '3.14'
Step-by-Step Solution
Solution:
  1. Step 1: Check Kotlin type names

    Kotlin uses capitalized type names like Float and Double.
  2. Step 2: Validate literal suffixes

    Float literals require an f suffix; 3.14f is valid for Float.
  3. Step 3: Analyze options

    val pi: Float = 3.14f correctly declares a Float variable with proper syntax.
  4. Final Answer:

    val pi: Float = 3.14f -> Option A
  5. Quick Check:

    Float type uses capital F and 'f' suffix [OK]
Quick Trick: Use capitalized types and suffixes for floats in Kotlin [OK]
Common Mistakes:
MISTAKES
  • Using lowercase type names like 'float'
  • Missing 'f' suffix for Float literals
  • Assigning string literals to numeric types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes