Menu
Question Index
...

Write a program to generate Gray code sequence given the number of elements required. Gray code is a binary representation in which next number is formed by changing only a single bit.

Input (int) Output (String[])
10 {0,1,11,10,110,111,101,100,1100,1101}
5 {0,1,11,10,110}
7 {0,1,11,10,110,111,101}
11 {0,1,11,10,110,111,101,100,1100,1101,1111}
-5 null
15 {0,1,11,10,110,111,101,100,1100,1101,1111,1110,1010,1011,1001}
0 {}



class GenerateGrayCodeSequence
{
    public static void main(String s[])
    {
        int number = 10;
        System.out.println("Gray code sequence is : ");
        String sequence[] = generateGrayCodeSequence(number);
        for (String n : sequence)
        System.out.print(n + " ");

    }


    public static String[] generateGrayCodeSequence(int number) {
    }
    

}

Doubts

Problems

Topic: Creating Objects for Primitive Data Types (Byte, Short)

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App