Advertisement
advictoriam

Untitled

Jan 15th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.48 KB | None | 0 0
  1. public class Numbers
  2. {
  3.    /**
  4.       Returns the number of digits in the binary
  5.       representation of a number
  6.       @param n a nonnegative number
  7.       @return the number of binary digits needed to
  8.       represent n
  9.    */
  10.    
  11.    // TODO: supply the method
  12.    public static int binaryDigits(int num)
  13.    {
  14.       return Integer.toBinaryString(num).length();
  15.    }
  16.    
  17.    public static void main(String[] args)
  18.    {
  19.       System.out.println(Numbers.binaryDigits(1000));
  20.    }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement