Skip to content

Commit 19176d9

Browse files
rename file
1 parent b7a0562 commit 19176d9

File tree

2 files changed

+28
-36
lines changed

2 files changed

+28
-36
lines changed

Maths/PowerOfTwoOrNot.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package Maths;
2+
3+
/**
4+
* A utility to check if a given number is power of two or not.
5+
* For example 8,16 etc.
6+
*/
7+
8+
public class PowerOfTwoOrNot {
9+
10+
public static void main(String[] args) {
11+
assert !checkIfPowerOfTwoOrNot(0);
12+
assert checkIfPowerOfTwoOrNot(1);
13+
assert checkIfPowerOfTwoOrNot(8);
14+
assert checkIfPowerOfTwoOrNot(16);
15+
assert checkIfPowerOfTwoOrNot(1024);
16+
}
17+
18+
19+
/**
20+
* Checks whether given number is power of two or not.
21+
*
22+
* @param number the number to check
23+
* @return {@code true} if given number is power of two, otherwise {@code false}
24+
*/
25+
public static boolean checkIfPowerOfTwoOrNot(int number) {
26+
return number != 0 && ((number & (number - 1)) == 0);
27+
}
28+
}

Others/PowerOfTwoOrNot.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)