LearnFrenzy
Sign in Take a free test

Object Class and Wrapper Classes · Predict the Output · Question 9

Converting numbers between bases Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

What is the output of the following Java program?

Main.java
public class Main {
    public static void main(String[] args) {
        System.out.println(Integer.toBinaryString(13) + " " + Integer.toHexString(4095) + " " + Integer.parseInt("777", 8) + " " + Integer.parseInt("1111", 2) + " " + Integer.toString(255, 36) + " " + Long.toHexString(-1L).length());
    }
}
  • A 1101 fff 511 15 73 16 Correct
  • B 1011 fff 511 15 73 16
  • C 1101 FFF 511 15 ff 16
  • D 1101 fff 777 15 73 8
Correct Answer: Option A

777 octal = 511; 255 in base 36 is "73" (7 × 36 + 3); -1L in hex is sixteen f's.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links