SHARE
TWEET

Untitled

advictoriam Jan 15th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top