Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the program?

public class Item24
{
    void execute()
    {
        String bits = Integer.toBinaryString(10);
        String hex = Integer.toHexString(255);
        System.out.println(bits + " " + hex);
    }

    public static void main(String[] args)
    {
        Item24 demo = new Item24();
        demo.execute();
    }
}

  • A.1010 and FF, in upper case
  • B.0b1010 and 0xff, with prefixes
  • C.10 and 255, unchanged
  • D.1010 and ff, in lower case

Answer: D

toBinaryString and toHexString return the digits alone, with no 0b or 0x prefix, and the hexadecimal letters are lower case. So 10 becomes 1010 and 255 becomes ff. Upper case would need toUpperCase() on the result.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.