Introduction / Context:
This evaluates the correct way of declaring floating-point literals in Java.
Concept / Approach:
- By default, floating literals like 1.0 are treated as double in Java.
- To assign to a float, append f or F.
- d or D indicates double explicitly.
- String literals like "1" cannot be assigned directly to float.
Step-by-Step:
Option A: Correct. "1F" explicitly declares a float.Option B: Incorrect. 1.0 defaults to double.Option C: Invalid type mismatch.Option D: Declares double literal with d.
Final Answer:
float f = 1F;
Discussion & Comments