fork(6) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static void getPermutations(int index, int[] output, ArrayList<int[]> solutions, int[] boxes)
  11. {
  12. if (index == output.length)
  13. {
  14. int[] temp = new int[output.length];
  15. System.arraycopy(output, 0, temp, 0, output.length);
  16. solutions.add(temp);
  17. return;
  18. }
  19. for (int b: boxes)
  20. {
  21. output[index] = b;
  22. getPermutations(index + 1, output, solutions, boxes);
  23. }
  24. }
  25.  
  26. public static void main (String[] args) throws java.lang.Exception
  27. {
  28. ArrayList<int[]> solutions = new ArrayList<>();
  29. int objectCount = 3;
  30. getPermutations(0, new int[objectCount], solutions, new int[]{-1, 0});
  31. for (int[] temp: solutions)
  32. {
  33. for (int i: temp)
  34. System.out.print(i + " ");
  35. System.out.println();
  36. }
  37. }
  38. }
Success #stdin #stdout 0.06s 380224KB
stdin
Standard input is empty
stdout
-1  -1  -1  
-1  -1  0  
-1  0  -1  
-1  0  0  
0  -1  -1  
0  -1  0  
0  0  -1  
0  0  0