package com.test; public class Pailie { public static void main(String[] args) { int[] ia = {1, 2, 3, 4,5,6,7,8,9,10}; int n = 4; System.out.println("排列结果 : "); permutation("",ia, n); // System.out.println("组合结果 : "); // combination(ia, n); } public static void permutation(String s, int[] ia, int n) { if(n == 1) { for(int i = 0; i < ia.length; i++) { System.out.println(s+ia[i]); } } else { for(int i = 0; i < ia.length; i++) { String ss = ""; ss = s+ia[i]+""; //建立没有第i个元素的子数组 int[] ii = new int[ia.length-1]; int index = 0; for(int j = 0; j < ia.length; j++) { if(j != i) { ii[index++] = ia[j]; } } permutation(ss, ii, n-1); } } } public static void combination(int[] ia, int n) { combination("", ia, n); } public static void combination(String s, int[] ia, int n) { if(n == 1) { for(int i = 0; i < ia.length; i++) { System.out.println(s+ia[i]); } } else { for(int i = 0; i < ia.length-(n-1); i++) { String ss = ""; ss = s+ia[i]+", "; //建立从i开始的子数组 int[] ii = new int[ia.length-i-1]; for(int j = 0; j < ia.length-i-1; j++) { ii[j] = ia[i+j+1]; } combination(ss, ii, n-1); } } } }

CST7777777 LV1
2022年4月28日
s491288234 LV1
2022年3月15日
ry970823 LV1
2021年12月9日
smallPipe LV2
2021年9月20日
seveny LV1
2021年9月19日
dongjing LV1
2021年9月2日
songii LV1
2021年8月26日
Madman LV10
2021年7月24日
zhengcloudtao LV1
2021年6月4日
liu3987741 LV8
2021年5月21日

Sotouch LV15
2024年12月9日
sjwc88 LV3
2024年12月4日
1112WHQ LV7
2023年11月3日
四十四十 LV3
2023年11月1日
微信网友_6705663532896256 LV1
2023年10月24日
wang123999 LV19
2022年7月8日
hanhao LV1
2022年6月1日
s491288234 LV1
2022年3月15日
ry970823 LV1
2021年12月9日
Zeorwyc LV8
2021年11月2日