Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CountOfBitsOne {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int number = input.nextInt();
- int count = 0;
- for (int i = 0; i < 32; i++) {
- int temp = 1<<i;
- temp = number & temp;
- if (temp >> i == 1) {
- count++;
- }
- }
- input.close();
- System.out.println(count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment