二进制输出

对于长度为5的一个01串,每一位可能是0或1,一共有32种可能。它们的前几个是:
00000
00001
00010
00011
00100
00101
请按从小到大的顺序输出这32种01串。

代码如下

public class C1 {
    public static void main(String[] args) {
        for(int i=0;i<32;i++) {
            String temp=Integer.toBinaryString(i);
            while(temp.length()<5) {
                temp=0+temp;
            }
            System.out.println(temp);
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_37964379/article/details/78639327