2016-10-23 9 views

答えて

0

はこれを試してみてください取得します。

int[] a = {1, 2}; 
int max = 1 << a.length; 
int[][] result = new int[max][]; 
for (int i = 0; i < max; ++i) { 
    result[i] = new int[Integer.bitCount(i)]; 
    for (int j = 0, b = i, k = 0; j < a.length; ++j, b >>= 1) 
     if ((b & 1) != 0) 
      result[i][k++] = a[j]; 
} 
System.out.println(Arrays.deepToString(result)); 

結果:

[[], [1], [2], [1, 2]] 
+0

ありがとうございます。 – Michael

関連する問題