统计一个整数中包含1的个数
2009-09-11 10:59 hailibu 阅读(244) 评论(0) 收藏 举报 1
private int CountOne(int num)
2
{
3
int count = 0;
4
while (num != 0)
5
{
6
count += num % 10 == 1 ? 1 : 0;
7
num /= 10;
8
}
9
return count;
10
}
private int CountOne(int num)2
{3
int count = 0;4
while (num != 0)5
{6
count += num % 10 == 1 ? 1 : 0;7
num /= 10;8
}9
return count;10
}


浙公网安备 33010602011771号