I want to find if a user entered number is a power of two or not.
My code doesn\'t work.
public class power_of_two { public static void main
A very simple solution.
int n = 8; // any integer and you can take it from user also for(;n>0;n++){ if(n%2 != 0) { System.out.println("not a power of two") return; } // if ends here n = n/2; }// for ends here System.out.println("power of two")