对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能。它们的前几个是:
00000
00001
00010
00011
00100
请按从小到大的顺序输出这32种01串。
输入格式
本试题没有输入。
输出格式
输出32行,按从小到大的顺序每行一个长度为5的01串。
样例输出
00000
00001
00010
00011
<以下部分省略>
package com.test01.xyx;
/**
* @author yuxing
* @create 2022-03-03-23:57
* @content:
*/
public class Test15 {
int arr[] = {0,0,0,0,0};
public static void main(String[] args) {
Test15 test15 = new Test15();
for (int i = 0 ;i < 32 ; i++){
for (int j = 0;j<5;j++){
System.out.print(test15.arr[j]);
}
System.out.println();
test15.arr[4]++;
test15.jinwei();
}
}
//进位
public void jinwei(){
for (int i = 0 ; i<arr.length ;i++){
if (arr[i]==2){
arr[i-1]++;
arr[i]=0;
}
}
}
}