方法一:
public class Number{
public int NumberOf1(int n){
int count = 0;
while(n!=0){
n=n&(n-1);
count++;
}
return count;
}
}
方法二:
public class Soluation{
public int Number(int n){
int result = 0;
char [] ch = Integer.toBinaryString(n).toCharArray();
for(int i=0;i<ch.length;i++){
if(ch[i]=='1'){
result ++;
}
}
return result;
}
}