Created
September 5, 2017 11:32
-
-
Save ponkin/745ce5681e779e1fc0c69961ea1ba991 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 class DivisionCheck { | |
private static final int FOUR_1 = 1 << 2; | |
private static final int FOUR_2 = 1 << 4; | |
private static final int FOUR_3 = 1 << 6; | |
private static final int FOUR_4 = 1 << 8; | |
private static final int FOUR_5 = 1 << 10; | |
private static final int FOUR_6 = 1 << 12; | |
private static final int FOUR_7 = 1 << 14; | |
private static final int FOUR_8 = 1 << 16; | |
private static final int FOUR_9 = 1 << 18; | |
private static final int FOUR_10 = 1 << 20; | |
private static final int FOUR_11 = 1 << 22; | |
private static final int FOUR_12 = 1 << 24; | |
private static final int FOUR_13 = 1 << 26; | |
private static final int FOUR_14 = 1 << 28; | |
private static final int FOUR_15 = 1 << 30; | |
public static void main(String args[]){ | |
System.out.printf("64 is power of two %s", isPowerOfFour(64)); | |
} | |
public static boolean isPowerOfFour(int x){ | |
switch(x){ | |
case FOUR_1: | |
case FOUR_2: | |
case FOUR_3: | |
case FOUR_4: | |
case FOUR_5: | |
case FOUR_6: | |
case FOUR_7: | |
case FOUR_8: | |
case FOUR_9: | |
case FOUR_10: | |
case FOUR_11: | |
case FOUR_12: | |
case FOUR_13: | |
case FOUR_14: | |
case FOUR_15: return true; | |
default: return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment