import java.io.*;
class BinaryCounter{
private String b;
private int binary;
public String binaryConverter(int binary){
this.binary = binary;
String temp;
temp = Integer.toBinaryString(binary);
return temp;
}
public String INCR(String b){
this.b = b;
char[] temp1 = new char[b.length()];
temp1 = b.toCharArray();
char[] temp2 = new char[temp1.length+1];
for(int h = 0 ; h < b.length() ; h++) temp2[h+1] = temp1[h];
int i = b.length();
while(temp2[i]=='1'){
temp2[i] = '0';
i--;
}
temp2[i] = '1';
return new String(temp2,1,b.length());
}
public static void main(String args[])throws Exception{
BinaryCounter b1 = new BinaryCounter();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter any number of your choice");
String b = br.readLine();
int h = Integer.parseInt(b);
String store = b1.binaryConverter(h);
String store1 = null;
for(int i = 0; i < 8 ; i++){
store1 = b1.INCR(store);
System.out.println("Incremented Number:"+store1);
store = store1;
}
}
}
***************OUTPUT**********************
C:\Users\dell\java>javac BinaryCounter.ja
C:\Users\dell\java>java BinaryCounter
Enter any number of your choice
12
Incremented Number:1101
Incremented Number:1110
Incremented Number:1111
Incremented Number:0000
Incremented Number:0001
Incremented Number:0010
Incremented Number:0011
Incremented Number:0100
C:\Users\dell\java>java BinaryCounter
Enter any number of your choice
100
Incremented Number:1100101
Incremented Number:1100110
Incremented Number:1100111
Incremented Number:1101000
Incremented Number:1101001
Incremented Number:1101010
Incremented Number:1101011
Incremented Number:1101100