本文共 268 字,大约阅读时间需要 1 分钟。
import java.util.Scanner;public class TestDemo{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int count = 0; while(n != 0) { count ++; n = n & (n-1); } System.out.println("1的个数为:" + count); } }
转载地址:http://vbsgz.baihongyu.com/