fork(11) 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 PermutingArray{
  9. static void permutingArray(java.util.List<Integer> arrayList, int element){
  10. for(int i = element; i < arrayList.size(); i++){
  11. java.util.Collections.swap(arrayList, i, element);
  12. permutingArray(arrayList, element+1);
  13. java.util.Collections.swap(arrayList,element, i);
  14. }
  15. if (element == arrayList.size() -1){
  16. System.out.println(java.util.Arrays.toString(arrayList.toArray()));
  17. }
  18. }
  19. public static void main(String[] args){
  20. PermutingArray.permutingArray(java.util.Arrays.asList(9,8,7,6,4), 0);
  21. }
  22. }
Success #stdin #stdout 0.11s 320448KB
stdin
Standard input is empty
stdout
[9, 8, 7, 6, 4]
[9, 8, 7, 4, 6]
[9, 8, 6, 7, 4]
[9, 8, 6, 4, 7]
[9, 8, 4, 6, 7]
[9, 8, 4, 7, 6]
[9, 7, 8, 6, 4]
[9, 7, 8, 4, 6]
[9, 7, 6, 8, 4]
[9, 7, 6, 4, 8]
[9, 7, 4, 6, 8]
[9, 7, 4, 8, 6]
[9, 6, 7, 8, 4]
[9, 6, 7, 4, 8]
[9, 6, 8, 7, 4]
[9, 6, 8, 4, 7]
[9, 6, 4, 8, 7]
[9, 6, 4, 7, 8]
[9, 4, 7, 6, 8]
[9, 4, 7, 8, 6]
[9, 4, 6, 7, 8]
[9, 4, 6, 8, 7]
[9, 4, 8, 6, 7]
[9, 4, 8, 7, 6]
[8, 9, 7, 6, 4]
[8, 9, 7, 4, 6]
[8, 9, 6, 7, 4]
[8, 9, 6, 4, 7]
[8, 9, 4, 6, 7]
[8, 9, 4, 7, 6]
[8, 7, 9, 6, 4]
[8, 7, 9, 4, 6]
[8, 7, 6, 9, 4]
[8, 7, 6, 4, 9]
[8, 7, 4, 6, 9]
[8, 7, 4, 9, 6]
[8, 6, 7, 9, 4]
[8, 6, 7, 4, 9]
[8, 6, 9, 7, 4]
[8,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