An integer that indicates the number of the output of the binary number 1 in. Wherein a negative number indicates a complement.
1 public class Solution { 2 public int NumberOf1(int n) { 3 String str = Integer.toBinaryString(n); 4 5 char [] c = str.toCharArray(); 6 7 int t = 0; 8 for(int i = 0; i < c.length; i++){ 9 if(c[i] == '1'){ 10 t++; 11 } 12 } 13 return t; 14 } 15 }