输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。 public class Solution { public int NumberOf1(int n) { String str = Integer.toBinaryString(n); char [] c = str.toCharArray(); int t = 0; for(int i = 0; i < c.length; i++){ if(c[i] == '1'){ t++; } } return t; } }