Learner Level
Implement the method isPowerOfTwo that checks whether an integer is a power of two.
A number is a power of two if it can be written as 2^k for some whole number k.
The task is designed to test careful handling of edge cases, not only the most common input.
- Return
falsefor zero and negative numbers. 1is a power of two.- You may use division or bit operations.
Repeatedly divide by two while the number is even. The final value must be one.