What will be the output of the following Java program? [code] class Output { public static void main(String args[])

Hương Trang

New member
What will be the output of the following Java program?
Code:
    class Output 
    {
        public static void main(String args[])
        {
	    Double i = new Double(257.578123456789);  
            float x = i.floatValue();
            System.out.print(x);
        }
    }
A. 0
B. 257.0
C. 257.57812
D. 257.578123456789
 
Answer: c
Explanation: floatValue() converts the value of wrapper i into float, since float can measure till 5 places after decimal hence 257.57812 is stored in floating point variable x.
Output:
Code:
$ javac Output.java
$ java Output
257.57812
This section of our 1000+ Java MCQs focuses on Type conversions, promotions and castings of Java Programming Language.
 

Tìm kiếm

Back
Top