This is a program to check if the input is power 2 or not. This program works fine for inputs up to 8 digits, but when I input, how 10 18 it does not work, what should I do?
import java.util.Scanner;
public class search {
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
int k ;
k = sc.nextInt();
for(int i = 0 ;i<k;i++){
long n ;
n = sc.nextInt();
if ((n > 0) && ((n & (n - 1)) == 0)){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
}
source
share