复习一下DFS实现全排列,具体思想见:https://www.cnblogs.com/chiweiming/p/9279858.html
public class Main{ static int arr[]=new int[6]; static int book[]=new int[6]; static int result=0; static void fun(int N){ if(N==6){ result++; for(int i=1;i<=5;i++){ System.out.print(arr[i]+" "); } System.out.println(); return; } for(int i=1;i<=5;i++){ //每个位置都尝试填入1~5 if(book[i]==0){ book[i]=1; arr[N]=i; fun(N+1); book[i]=0; } } } public static void main(String[] args) { fun(1); System.out.println(result); } }