01.public class Rank {
02. public static void main(String[] args) {
03. int[] array = { 7, 9, 5, 8 };
04. boolean[] isSelected = new boolean[array.length];
05. int[] array2 = new int[array.length];
06. for (int i = 0; i < isSelected.length; i++) {
07. isSelected[i] = false;
08. }
09. rankArray(array, isSelected, array2, 0);
10. }
11.
12. public static void rankArray(int[] array, boolean[] isSelected,
13. int[] array2, int length) {
14.
15. if (array.length == length) {
16. for (int i : array2) {
17. System.out.print(i + ",");
18. }
19. System.out.println();
20. return;
21. }
22. for (int i = 0; i < isSelected.length; i++) {
23. if (isSelected[i]) {
24. continue;
25. }
26. isSelected[i] = true;
27. array2[length] = array[i];
28. rankArray(array, isSelected, array2, length + 1);
29. isSelected[i] = false;
30. }
31. }
32.}
你试一下! |