Bits Counter in java
1. User inputs a positive base 10 integer, greater than zero, determine how many one bits are in the binary equivalent. Then determine how many numbers between zero and the given number contain the same number of one bits. For example, the number 12 expressed as a binary number (1100) has 2 one bits. Between 0 and 12 there are 5 other numbers having 2 one bits when expressed as a binary number. These are: 3 (11), 5 (101), 6 (110), 9 (1001), 10 (1010). Test data: Input Output 8 8 in binary has 1 1-bits. There are 3 other numbers with 1 1-bits between 0 and 8. 12 12 in binary has 2 1-bits. There are 5 other numbers with 2 1-bits between 0 and 12. 17 17 in binary has 2 1-bits. There are 6 other numbers with 2 1-bits between 0 and 17. 55 55 in binary has 5 1-bits. There are 2 other numbers with 5 1-bits between 0 and 55. I already solve this problem but i want to know if there is more efficient way to do this. Below is the program written import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a number:"); int num; int obits=0,zbits=0,tbits=0; num = input.nextInt(); int[] bin = new int[10]; int j = 0; int z=num; while (num > 0) { bin[j] = num % 2; num = num / 2; j++; } for(int i=0;i<j;i++){ if(bin[i]==1){ tbits++; } if(bin[i]==0){ zbits++; } } int total=0; int y=z-1; int[] others=new int[z]; for(int i=y;i>0;i--){ int n=i; int x=0,num1=0,zeros=0; while(n>0){ others[x] = n%2; n = n/2; x++; } for(int g=0;g<=x;g++){ if(others[g]==1){ num1+