博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
写一个函数返回参数二进制中 1 的个数
阅读量:726 次
发布时间:2019-03-21

本文共 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/

你可能感兴趣的文章