题解 | #查找输入整数二进制中1的个数#
查找输入整数二进制中1的个数
https://www.nowcoder.com/practice/1b46eb4cf3fa49b9965ac3c2c1caf5ad
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.time.LocalDateTime; import java.util.*; import java.util.stream.IntStream; import java.util.stream.Stream; import static java.util.stream.Stream.*; public class Main { public static void main(String[] args) throws IOException { //testCompletePack(); testTh(); } private static void testTh() throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String str; while ((str = bf.readLine()) != null) { int parseInt = Integer.parseInt(str); String s = Integer.toBinaryString(parseInt); System.out.println(s.length() - s.replaceAll("1", "").length()); } } }