something is wrong with my first loop where i find the value of the variable loops. when i comment out that particular loop and run the rest of the code, the code runs perfectly but when i run the code with that for loop, i am getting different answers. please help.
code:
public static void main(String [] args){
Scanner sc = new Scanner (System.in);
System.out.print("number : ");
int n = sc.nextInt();
int inc = 0;
int loops = 0;
**// problem
for(int i = 0; n>0; i++){
int b = n>>=i;
loops = i;
}**
for (int i = 0; i<=loops; i++){
int bit = 1<<i;
if((bit & n) == 0){
}else{
inc = inc + 1;
}
}
if (inc==1){
System.out.println("power");
}else{
System.out.println("not power");
}
}