- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTotalone.java
More file actions
Latest commit
25 lines (22 loc) · 439 Bytes
/
Copy pathTotalone.java
File metadata and controls
25 lines (22 loc) · 439 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
packagecom.test;
importjava.util.Scanner;
publicclassTotalone {
/**
* @author wyl
* 判断一个整数的二进制位中有多少个1
*/
staticintkk=0;
publicstaticvoidmain(String[] args) {
Scannerscan = newScanner(System.in);
intvalue = scan.nextInt();
intsum = count(value);
System.out.println(sum);
}
privatestaticintcount(intvalue) {
while(value!=0){
value = value&(value-1);
kk++;
}
returnkk;
}
}