思路:该数和1进行与操作,得到尾数值
判断尾数是否为1,进行记录,直到右移完成
private static void oneCount(int n){ int count= 0; while (n > 0){ int end = n & 1; if(end == 1){ count++; } n = n >> 1; } System.out.println(count); }