ProtyayMnd50 revised this gist . Go to revision
1 file changed, 19 insertions
PowerofTwo.java(file created)
@@ -0,0 +1,19 @@ | |||
1 | + | import java.util.*; | |
2 | + | import java.io.*; | |
3 | + | ||
4 | + | class Main { | |
5 | + | public static String PowersofTwo(int num) { | |
6 | + | if (num > 0 && (num & (num - 1)) == 0) { | |
7 | + | return "true"; | |
8 | + | } else { | |
9 | + | return "false"; | |
10 | + | } | |
11 | + | } | |
12 | + | ||
13 | + | public static void main (String[] args) { | |
14 | + | System.out.println(PowersofTwo(4)); // Output: true | |
15 | + | System.out.println(PowersofTwo(124)); // Output: false | |
16 | + | System.out.println(PowersofTwo(16)); // Output: true | |
17 | + | System.out.println(PowersofTwo(22)); // Output: false | |
18 | + | } | |
19 | + | } |
Newer
Older