Last active 1748455131

PowerofTwo.java Raw
1import java.util.*;
2import java.io.*;
3
4class 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}
20