Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BinaryDigitsCount {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int number = Integer.parseInt(scanner.nextLine());
- int bynaryNumber = Integer.parseInt(scanner.nextLine());
- int count = 0;
- while (number != 0) {
- int leftOver = number % 2;
- if (leftOver == bynaryNumber) {
- count++;
- }
- number = number / 2;
- }
- System.out.println(count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment