Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Homework2;
- import java.util.*;
- public class CountOfEqualBitPairs {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int num = sc.nextInt();
- int count = 0;
- while ((num >> 1) != 0) {
- if (((num & 1) == 1) && ((num >> 1) & 1) == 1) {
- count++;
- }
- else if (((num & 1) == 0) && ((num >> 1) & 1) == 0) {
- count++;
- }
- num >>= 1;
- }
- System.out.println(count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement