Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Problem_8_CountOfEqualBitPairs {
- public static void main(String[] args) {
- Scanner scan= new Scanner(System.in);
- int num= scan.nextInt();
- String str= Integer.toBinaryString(num);
- System.out.println(num);
- System.out.println(str);
- // int a=0;
- // int b=0;
- long count=0;
- for (int i = 0; i < str.length() ; i++) {
- if (((num >> i ) & 1) == 1 && ((num >> (i+1)) & 1) ==1) {
- count++;
- }
- else if (((num >> i ) & 1) == 0 && ((num >> (i+1)) & 1) ==0) {
- count++;
- }
- }
- System.out.println("count: " + count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement