- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountNumOfOne.java
More file actions
Latest commit
23 lines (21 loc) · 516 Bytes
/
Copy pathcountNumOfOne.java
File metadata and controls
23 lines (21 loc) · 516 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
packageBit_Manipulation;
importjava.util.Scanner;
publicclasscountNumOfOne {
publicstaticvoidmain(String... args){
Scannersc=newScanner(System.in);
System.out.println("Enter the Number: ");
intnum=sc.nextInt();
System.out.print("The Number of one's in : "+num+" ("+Integer.toBinaryString(num)+")");
intresult=countOne(num);
System.out.println(" is : "+result);
sc.close();
}
staticintcountOne(intn){
intcount=0;
while(n>0){
n=n&(n-1);
count++;
}
returncount;
}
}