Menu
Topics Index
...
`

Colours


If you need explanation Read this topic

If you need Answer Take test on this topic

Colours
What will be the output of the following program?
public class Colours {
    public static void main(String args[]) {
        int pink = 'p';
        int blue = 'B';
        String red = Integer.toBinaryString(pink);
        String green = Integer.toOctalString(blue);
        System.out.print(red + " " + green);
    }
}

A. 1111000 66
B. 1110000 66
C. 1110000 102
D. 1111000 102
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.

Answer is c...bcoz ascii values of p & B are 112 & 66 respectively...Integer.toBinaryString method converts the ascii value of p to base 2 conversion...which yields 1110000..and tooctal method converts 66 to octal conversion which yields..102..thus the result would be C

Posted by Sneha Rapool    2014-02-11 12:41:46


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-02-12 03:50:36


© meritcampus 2019

All Rights Reserved.

Open In App