logo Practice-It logo

isPowerOfTwo

Language/Type: Java method basics return
Author: Roy McElmurry (on 2010/12/28)

Write a static method isPowerOfTwo that takes an integer n as an argument, and that returns true if n is a power of two, and otherwise false. If n is zero or negative, return false. Note that isPowerOfTwo(1) should return true, since 20=1.

Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.