Menu
Topics Index
...
`

Conversions2349


If you need explanation Read this topic

If you need Answer Take test on this topic

Conversions2349
What will be the output of the following program?
public class AdditionOfData {
    public static void main(String[] args) {
        String data = "20", dataI;
        int i = Integer.parseInt(data);
        dataI = Integer.toHexString(i);
        Short s = Short.parseShort(dataI);
        float f = Float.parseFloat(data);
        long l = Long.parseLong(data);
        System.out.println(i + s + f + l);
    }
}

A. 80.0
B. 74.0
C. Compilation Error
D. Runtime Error
Topic: Converting Numbers to and from Strings In Java

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.

Option B, here i=20, dataI will be 14(1X16+4X1=20) , s=14 (parseshort), f=20, l=20 thus giving an output of 74.

Posted by Yashasvi Bandi    2014-05-15 04:12:19


Congratulations  Yashasvi Bandi. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-05-16 04:27:11


© meritcampus 2019

All Rights Reserved.

Open In App