@@ -0,0 +1,846 @@
+package com.coderevisited.bits;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Apublic class GenerateNBitGrayCodes%0A%7B%0A    public static void main(String%5B%5D args)%0A    %7B%0A        List%3CString%3E list = generateGrayCode(5);%0A        for (String code : list) %7B%0A            System.out.println(code);%0A        %7D%0A    %7D%0A%0A    private static List%3CString%3E generateGrayCode(int n)%0A    %7B%0A        if (n == 1) %7B%0A            List%3CString%3E list = new ArrayList%3C%3E();%0A            list.add(%220%22);%0A            list.add(%221%22);%0A            return list;%0A        %7D%0A        List%3CString%3E prev = generateGrayCode(n - 1);%0A        List%3CString%3E list = new ArrayList%3C%3E();%0A        for (String str : prev) %7B%0A            list.add(%220%22 + str);%0A        %7D%0A%0A        for (int i = prev.size() - 1; i %3E= 0; i--) %7B%0A            list.add(%221%22 + prev.get(i));%0A        %7D%0A%0A        return list;%0A    %7D%0A%7D%0A

Generate N-Bit Gray Codes