查找输入整数二进制中1的个数
查找输入整数二进制中1的个数
http://www.nowcoder.com/questionTerminal/1b46eb4cf3fa49b9965ac3c2c1caf5ad
import java.util.Scanner; public class Main { private int findNumberOf1( int num) { int count = 0; while (num != 0) { if ((num & 1) == 1) count++; num = num >>> 1; } return count; } public Main() { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { int num = in.nextInt(); int res = findNumberOf1(num); System.out.println(res); } } public static void main(String[] args) { Main solution = new Main(); } }