古得曼_63b6

关注

Give a very good method to count the number of ones in a

古得曼_63b6

关注

阅读 96

2022-08-01


Give a very good method to count the number of ones in a "n" (e.g. 32) bit number.

 

public class Count {
public static void main(String args[])
{
int count=0;
int num=1101011011;
for(int i=0;i<6;i++)//统计的位数
{
if(num%Math.pow(10,i+1)==Math.pow(10,i))
count++;
num=(int) (num-num%Math.pow(10,i+1));

}

System.out.print(count);

}

}

 

相关推荐

玩物励志老乐

css 的动画设置 very good

玩物励志老乐 26 0 0

夕阳孤草

带着夜色花香的小诗 Very good!

夕阳孤草 91 0 0

TiaNa_na

1325 K-Good Number

TiaNa_na 39 0 0

就是耍帅

LeetCode1504. Count Submatrices With All Ones

就是耍帅 10 0 0

八卦城的酒

[leetcode] 1534. Count Good Triplets

八卦城的酒 72 0 0

alonwang

1-20 very good饭店的分类Id选择

alonwang 26 0 0

49路末班车

[leetcode] 1530. Number of Good Leaf Nodes Pairs

49路末班车 47 0 0

ZMXQQ233

圖像及編程常用網址,作為收藏(Very Good)

ZMXQQ233 114 0 0

开源分享

LeetCode-1248. Count Number of Nice Subarrays

开源分享 55 0 0

岁月不饶人老不正经

LintCode 0003 统计数字(count number)

岁月不饶人老不正经 50 0 0

精彩评论(0)

0 0 举报