题解 | #查找输入整数二进制中1的个数#
查找输入整数二进制中1的个数
http://www.nowcoder.com/practice/1b46eb4cf3fa49b9965ac3c2c1caf5ad
import java.util.; import java.io.;
public class Main{
public static void main(String[] args) {
final InputStreamReader reader = new InputStreamReader(System.in);
try (final BufferedReader br = new BufferedReader(reader)) {
String str_number;
while((str_number=br.readLine())!=null){
int number = Integer.parseInt(str_number);
String str= Integer.toBinaryString(number);
String str2 = str.replaceAll("[1]","");
System.out.println(str.length() - str2.length());
}
}catch (IOException e ){
System.out.println(e.getMessage());
}
}
}