逻辑判断题,有很多个条件,1,0表示真,假,遍历所有的可能情况,递归操作。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
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