Menu
Topics Index
...
`

Conversions 2354


If you need explanation Read this topic

If you need Answer Take test on this topic

Conversions 2354
What will be the output of the following program?
public class Conversions {
    public static void main(String args[]) {
        int cat = 15;
        String dog = Integer.toBinaryString(cat);
        String monkey = Integer.toOctalString(cat);
        String cow = Integer.toHexString(cat);
        System.out.print(dog + " " + monkey + " " + cow);
    }
}

A. 1111 17 f
B. 1111 15 f
C. 1111 017 f
D. 1111 15 g
E. Compilation Error or 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.

prints the respective binary , octal and hex equvilalent of number 15(i.e integer)
binary = 1111(binarystring)
octal=17(octal string)

Posted by Kittu Manoj    2014-04-01 12:45:34


hex=f(hex string)

Posted by Kittu Manoj    2014-04-01 12:45:44


answer is A

Posted by Kittu Manoj    2014-04-01 12:45:52


ans : A
toBinarystring returns corresponding binary string....
here "1111"
toOctalstring returns corresponding octal value..
here "17"
tohexstring returns corresponding hexa decimal value..
here "f"
so finally ..1111 17 f is printed

Posted by Ananda Kumar    2014-04-01 13:13:56


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

Posted by Merit Campus    2014-04-02 04:42:53


© meritcampus 2019

All Rights Reserved.

Open In App