题解 | #求int型正整数在内存中存储时1的个数#
求int型正整数在内存中存储时1的个数
http://www.nowcoder.com/practice/440f16e490a0404786865e99c6ad91c9
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class HJ15_cunchugeshu {
//求int型正整数在内存中存储时1的个数
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int input = Integer.parseInt(bf.readLine());
bf.close();
int num = 0;
if(input!=0){
while (input!=1){
if(input%2==1){
num++;
}
input=input/2;
}
num++;
System.out.println(num);
}else {
System.out.println(0);
}
}
}