HTML/JavaScript小工具

HTML/JavaScript小工具

2021年7月12日 星期一

集合的全排列

 public class Test1 {


public static void main(String[] args) {

// TODO Auto-generated method stub

int[] array = {15,16,17};

//2^3 = 8

//001 1

//010 2

//011 3

//100 4 

//101 5  

//110 6

//111 7

//000 0

for(int s=1;s<(1<<array.length);s++) {

for (int j = 0; j < array.length;j++) {

if ( (s & (1<<j)) > 0) {

System.out.print(array[j]+" ");

}

}

System.out.println();

}

}


}

沒有留言:

張貼留言