Home / Java Programming / Language Fundamentals :: Discussion

Discussion :: Language Fundamentals

  1. Which three are valid declarations of a float?

    1. float f1 = -343;
    2. float f2 = 3.14;
    3. float f3 = 0x12345;
    4. float f4 = 42e7;
    5. float f5 = 2001.0D;
    6. float f6 = 2.81F;

  2. A.
    1, 2, 4
    B.
    2, 3, 5
    C.
    1, 3, 6
    D.
    2, 4, 6

    View Answer

    Workspace

    Answer : Option C

    Explanation :

    (1) and (3) are integer literals (32 bits), and integers can be legally assigned to floats (also 32 bits). (6) is correct because (F) is appended to the literal, declaring it as a float rather than a double (the default for floating point literals).

    (2), (4),and (5) are all doubles.


Be The First To Comment