利用Integer的方法转换为二进制,然后字符串处理即可

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String string = Integer.toBinaryString(s.nextInt());
        System.out.println(string.length() - string.replace("1","").length());
    }
}