直接调API:Integer.bitCount()
import java.util.Scanner;
/**
* 【查找输入整数二进制中1的个数】
*
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int nextInt = sc.nextInt();
System.out.println(Integer.bitCount(nextInt));
}
}
}