选择题
自连接使用一张表
编程题
题目1
import java.util.Scanner;
public class Main {
public static int res(int n) {
StringBuffer s = new StringBuffer();
while(n!=0) {
s.append(n%2);
n/=2;
}
int sum = 0;
String ss = s.reverse().toString();
for(int i=0;i<ss.length();i++) {
if(s.charAt(i) == '1')
sum++;
}
return sum;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
int n = sc.nextInt();
System.out.println(res(n));
}
sc.close();
}
}