I have tried writing a java program to find a number is power of two the one which i mentioned below.
I am passing number as 2147483647 and the output of my program is returning true instead of false.
Can anyone explain what concept I am missing here and how to correct it.
Program
class Solution {
public boolean isPowerOfTwo(int n) {
int num = 0;
int p = 0;
while(num <= n){
num = (int) Math.pow(2,p);
p++;
if(num == n){
return true;
}
}
return false;
}
}
public static void main(String[] args) {
enter code here
boolean val = isPowerOfTwo(2147483647);
}