Advertisement
momodishev

CountOfEqualBitPairs

May 16th, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class _08_CountOfEqualBitPairs {
  5.  
  6.     public static void main(String[] args) {
  7.        
  8.         Scanner inputNum = new Scanner(System.in);
  9.         long number = inputNum.nextLong();
  10.         String binary = Long.toBinaryString(number);
  11.         long binRep = Long.parseLong(binary);
  12.         long binSubtr = binRep;
  13.         long count = 0;
  14.        
  15.         for (int i = 0; i < binary.length(); i++) {
  16.             long left = binSubtr;
  17.             left = binSubtr%100;
  18.             binSubtr/=10;
  19.             if (left==11||left==0) {
  20.                 count++;
  21.             }
  22.         }
  23.         System.out.println(count);
  24.     }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement