Menu
Question Index
...

What will be the output of the following program?

class FloatConversion
{
    public static void main(String args[])
    {
        int i = 44;
        float f = 98.42f;
        double d = 103.67;
        
        f = (float) i;
        d = (double) f;
        i = (int) d;

        System.out.println("i = " + i);
        System.out.println("f = " + f);
        System.out.println("d = " + d);
    }
}


i = 44
f = 44.0
d = 44.0
i = 103.67
f = 44
d = 98.42
Compilation error since the initialization of double d is wrong. It should be 103.67d.
Compilation errors since we are casting integer to float and float to double.

Doubts

Problems

Topic: Type Casting In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App