Get comprehensive answers to your questions with the help of IDNLearn.com's community. Ask your questions and get detailed, reliable answers from our community of experienced experts.
Answer:
public static boolean isPowerOfTwo(int n) {
long exp = Math.round(Math.log(n) / Math.log(2));
return Math.pow(2, exp) == n;
}
Explanation:
The opposite of power-of-2 is the 2-log, which is calculated using any log divided by log(2).
I'm sure you can do the input part yourself!