Created
May 12, 2015 15:18
-
-
Save kidinov/5a376b98b6c49a2ffb18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
System.out.println(String.format("10 is power of two = %s", isPowerOfTwo(10))); | |
System.out.println(String.format("8 is power of two = %s", isPowerOfTwo(8))); | |
System.out.println(String.format("-3 is power of two = %s", isPowerOfTwo(-3))); | |
System.out.println(String.format("3.14 is power of two = %s", isPowerOfTwo(3.14f))); | |
} | |
public static boolean isPowerOfTwo(float arg) { | |
if (Math.floor(arg) != arg) { | |
return false; | |
} | |
if (arg == 1) { | |
return true; | |
} | |
return isPowerOfTwo(arg / 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment