Generating N | Java program Generating N - bit Gray Code starting from K ; Function to Generating N - bit Gray Code starting from K ; Generate gray code of corresponding binary number of integer i . ; Driver code
class GFG { static void genSequence ( int n , int val ) { for ( int i = 0 ; i < ( 1 << n ) ; i ++ ) { int x = i ^ ( i >> 1 ) ^ val ; System . out . print ( x + " ▁ " ) ; } } public static void main ( String [ ] args ) { int n = 3 , k = 2 ; genSequence ( n , k ) ; } }