Menu
Topics Index
...
`

Integer to different radix


If you need explanation Read this topic

If you need Answer Take test on this topic

Integer to different radix
What will be the output of the following program?
public class Conversion {
    public static void main(String[] args) {
        int i = 20;
        System.out.println(Integer.toBinaryString(i) + ", " + Integer.toOctalString(i) + ", " + Integer.toHexString(i));
    }
}

A. 10100, 22, AA
B. 10100, 24, 14
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.

answer is B..The number 20 can be expressed as:
16 + 4
So, the answer is: 10100 in binary..In octal it is 24,hex it is 14..thus the answer is B..

Posted by Sneha Rapool    2014-05-14 13:19:47


Ans is B as i is 20 and is converted to binary octal and hex values and printed as a string

Posted by Bharath Yelchuri    2014-05-14 13:19:55


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

Posted by Merit Campus    2014-05-15 04:29:48


© meritcampus 2019

All Rights Reserved.

Open In App