Bird
0
0

Which of the following is the correct way to declare a Double variable with value 2.71828 in Kotlin?

easy📝 Syntax Q3 of 15
Kotlin - Data Types
Which of the following is the correct way to declare a Double variable with value 2.71828 in Kotlin?
Aval e: Double = 2
Bval e: Double = 2.71828
Cval e: Double = 2.71828L
Dval e: Double = 2.71828f
Step-by-Step Solution
Solution:
  1. Step 1: Understand Kotlin suffixes for number types

    Float literals use 'f', Long literals use 'L', Double literals have no suffix.
  2. Step 2: Choose the correct syntax for Double

    Assigning 2.71828 without suffix to a Double variable is correct.
  3. Final Answer:

    val e: Double = 2.71828 -> Option B
  4. Quick Check:

    Double literal = no suffix [OK]
Quick Trick: Double literals have no suffix; Float uses 'f', Long uses 'L' [OK]
Common Mistakes:
MISTAKES
  • Adding 'f' suffix to Double
  • Using 'L' suffix for decimals
  • Assigning integer without decimal to Double

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes