题目描述
二级制中1的个数
JAVA 代码
import java.util.*;
import java.io.*;
class Main{
static int N;
static int[] a = new int[N];
public static void main(String args[])throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(in.readLine());
a = Arrays.asList(in.readLine().split(" ")).stream().mapToInt(Integer:: parseInt).toArray();
for(int i = 0; i < n; i ++){
int s = 0;
while(a[i]!=0){
//lowbit 操作, x & -x ==> 返回 x 的最后一位1
a[i] -= a[i] & - a[i];
s++;
}
System.out.print(s + " ");
}
}
}