判断是不是2的n次方

public class data{
public static void main(String[] args) {
NewClass nc = new NewClass();
nc.CF(16);
}
}

class NewClass {

public void CF(int x) {
     int a = x;
    while (true) {
       
        int j = x % 2;
        x = x / 2;
        if (j == 1) {
            break;
        }
        if (x == 2) {
            System.out.println(a);
            break;
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_43011881/article/details/87912511