Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CountOfEqualBitPairs {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int number = input.nextInt();
- int zeroCount = 0;
- int oneCount = 0;
- int pairs = 0;
- while (number != 0) {
- int digit = number % 2;
- if (digit == 0) {
- zeroCount++;
- if (zeroCount >= 2) {
- pairs++;
- zeroCount--;
- }
- oneCount = 0;
- }
- else if (digit == 1) {
- oneCount++;
- if (oneCount >= 2) {
- pairs++;
- oneCount--;
- }
- zeroCount = 0;
- }
- number /= 2;
- }
- System.out.println(pairs);
- input.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement