Menu
Topics Index
...
`

How many coins


If you need explanation Read this topic

If you need Answer Take test on this topic

How many coins
What will be the output of the following program?
public class Coins {
    public static void main(String[] args) {
        String input = "50";
        Short coins = Short.parseShort(input + 10);
        short total = Short.parseShort(input, 16);
        System.out.println(coins + " " + total);
    }
}

A. 5010 80
B. 60 96
C. Compilation Error
D. Runtime Error
Topic: Creating Objects for Primitive Data Types (Byte, Short)

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:A  coins=" string concatinnation" total="80" 50 in hexADECIMAL FORMAT

Posted by Indrasena Reddy    2014-02-11 03:30:29


Compilation Error

Posted by Prudhvi Raj    2014-02-11 04:26:16


Ans is :A, coins=5010, because 50 is treated as string ,so it cant add to 10. and total=80, because, in parseShort method 16 is radix of input value so. total=80.

Posted by Mallikarjuna Rao    2014-02-11 06:00:21


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

Posted by Merit Campus    2014-02-12 03:49:33


© meritcampus 2019

All Rights Reserved.

Open In App