Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Numbers
- {
- /**
- Returns the number of digits in the binary
- representation of a number
- @param n a nonnegative number
- @return the number of binary digits needed to
- represent n
- */
- // TODO: supply the method
- public static int binaryDigits(int num)
- {
- return Integer.toBinaryString(num).length();
- }
- public static void main(String[] args)
- {
- System.out.println(Numbers.binaryDigits(1000));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement