遍历所有01序列
逻辑判断题,有很多个条件,1,0表示真,假,遍历所有的可能情况,递归操作。
/**
* Created by Methol on 2015/4/8.
*/
public class Main {
static int a[] ={0,0,0};
public static void show(){
for (int i = 0; i < a.length; i++) {
System.out.print(a[i]+" ");
}
System.out.println();
}
public static void f(int i){
if(i>=a.length){
//这里写操作
show();
return;
}
a[i] = 0;
f(i+1);
a[i] = 1;
f(i+1);
}
public static void main(String []args){
f(0);
}
}
输出结果:
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1