File tree 1 file changed +35
-0
lines changed
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ package easy ;
2
+
3
+ /**
4
+ * Have the function PowersofTwo(num) take the num parameter being passed
5
+ * which will be an integer and return the string true if it's a power of two.
6
+ * If it's not return the string false.
7
+ * For example if the input is 16 then your program should return the string true
8
+ * but if the input is 22 then the output should be the string false.
9
+ */
10
+ public class PowersOfTwo {
11
+
12
+ /**
13
+ * Powers of Two function.
14
+ *
15
+ * @param num input number
16
+ * @return the string true if it's a power of two.
17
+ */
18
+ private static String powerOfTwo (int num ) {
19
+ int bitwise = num & num - 1 ;
20
+ return num != 0 && bitwise == 0 ? "true" : "false" ;
21
+ }
22
+
23
+ /**
24
+ * Entry point.
25
+ *
26
+ * @param args command line arguments
27
+ */
28
+ public static void main (String [] args ) {
29
+ var result1 = powerOfTwo (15 );
30
+ System .out .println (result1 );
31
+ var result2 = powerOfTwo (64 );
32
+ System .out .println (result2 );
33
+ }
34
+
35
+ }
You can’t perform that action at this time.
0 commit comments