diff --git a/algorithms/Java/queues/Generate Binary numbers b/algorithms/Java/queues/Generate Binary numbers new file mode 100644 index 00000000..2064ca5b --- /dev/null +++ b/algorithms/Java/queues/Generate Binary numbers @@ -0,0 +1,23 @@ +import java.util.LinkedList; +import java.util.Queue; +public class generatebinary { + public static void genrating(int n,Queue sb) + { + sb.add("1"); + + while(n-->0) + { + String s1=sb.peek(); + System.out.println(s1); + sb.remove(); + String s2=s1; + sb.add(s1+"0"); + sb.add(s2+"1"); + } + } + public static void main(String[] args) { + int n=5; + Queue sb=new LinkedList(); + genrating(n,sb); + } +}