int n=4,m=n-1;
String[] options = {"A","B","C","D"};
int choice[]={-1,-1,-1,-1};
int flag=0;
while(flag>-1) {
choice[flag] = choice[flag]+1;
if (choice[flag]>m) {
choice[flag]=-1;
flag--;
continue;
}
if(flag==m) {
for (int p:choice)
System.out.print(options[p]+" ");
System.out.println();
}
else
flag++;
}
效果就是把所有我排列形式枚举出来。