Menu
Topics Index
...
`

AbCdEfGh


If you need explanation Read this topic

If you need Answer Take test on this topic

AbCdEfGh
What will be the output of the following program?
public class AbCdEfGh {
    public static void main(String args[]) {
        try {
            Float f1 = new Float("150.0");
            int x = f1.intValue();
            byte b = f1.byteValue();
            double d = f1.doubleValue();
            System.out.println(x + b + d);
        } catch (NumberFormatException e) {
            System.out.println("Wrong number");
        }
    }
}

A. 194.0
B. 278.0
C. 450.0
D. Wrong number
E. Compilation Error or Runtime Error
Topic: Java Double Class And Java Float Class

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans id D.. becz three diff data types are adding.. so it leads to exception..

Posted by Om Prakash Om    2013-05-17 12:34:53


answer is a : values are converted accordiingly and x+b+d is 194.0

Posted by Mahesh Kumar    2013-05-17 12:36:17


option a is answer because values of int is 150 and double is also 150 but of byte value is -106

Posted by Sai Lalitha Renduchintala    2013-05-17 12:36:32


ans is a: as byte value of corersponding number is -106 so the final sum would b 194

Posted by Krishna Murthy    2013-05-17 12:37:28


Ans is a:int x consist of 150,byte b consists of -106,double d consists of 150.0  ---Hence the o/p is 194.0 .1)when the expression consists only numerical datatypes the operation is done in integer format.2)when the expression consists only floating point  datatypes the operation is done in double format.3)when the expression consists both numerical and floating point datatypes the operation is in double format

Posted by Indrasena Reddy    2013-05-17 13:53:16


Congratulations Sai Lalitha. You are today's daily dose winner. Please send us your mobile details and we will process your recharge on Monday after considering the new likes.

Posted by Merit Campus    2013-05-17 15:18:44


thanQ merit campus, got the recharge :)

Posted by Sai Lalitha Renduchintala    2013-05-20 16:50:01


© meritcampus 2019

All Rights Reserved.

Open In App