title: How to write a recursive function that produces Gray codes
body: <p>I am working with gray code and I got almost everything, but when the code run, like 1-bit or 2-bit it only prints out 0000 rather than 00 01 11 10. </p>
  
  <pre><code>class GrayCode {
  
       static void genGC(int n){
            if(n == 0){
                 System.out.println(n);
            }
            else{
                 genGC(n-1);
                 genGC(n-1);
            }
       }
  
       public static void main(String[] args) {
            int a = 2;
            genGC(a);
       }
  }
  </code></pre>