Advertisement
velio84

_08_CountOfEqualBitPairs

Sep 8th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. package Homework2;
  2. import java.util.*;
  3.  
  4. public class CountOfEqualBitPairs {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner sc = new Scanner(System.in);
  8.         int num = sc.nextInt();
  9.         int count = 0;
  10.        
  11.         while ((num >> 1) != 0) {
  12.             if (((num & 1) == 1) && ((num >> 1) & 1) == 1) {
  13.                 count++;
  14.             }
  15.             else if (((num & 1) == 0) && ((num >> 1) & 1) == 0) {
  16.                 count++;
  17.             }
  18.             num >>= 1;
  19.         }
  20.         System.out.println(count);
  21.  
  22.     }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement