List of all binary combinations for a number in Java

后端 未结 6 1076
后悔当初
后悔当初 2021-01-14 05:15

I am working on a project involving \"Dynamic Programming\" and am struck on this trivial thing, please help.

Suppose I take 4 as an input, I want to display somethi

6条回答
  •  庸人自扰
    2021-01-14 05:50

    int x = 5;
    
    for(int i = 0; i < (1 << x); i++){ 
     System.out.println(Integer.toBinaryString(i)); 
    }
    

提交回复
热议问题