1xyyy

按照你的要求编写的求x,y指定长度的所有排列组合的Java程序如下

import?java.util.ArrayList;

import?java.util.List;

public?class?EE?{

public?static?void?combination(List<String>?list,?String?sNumbers,?String?sPath,?int?ALen)

{

if?(sPath.length()==?ALen)

{

list.add(sPath);

return;

}

for(int?i=0;i<sNumbers.length();i++)

{

combination(list,sNumbers,sPath?+sNumbers.substring(i,i+1),?ALen);

}

}

public?static?void?main(String[]?args)?{

List<String>?output?=?new?ArrayList<String>();

System.out.println("组合");

combination(output,"xy",?"",?5);

for(String?s:?output)

System.out.print(s+"?");

System.out.println();

System.out.println("***"+output.size()+"个");

}

}

运行结果

组合

xxxxx xxxxy xxxyx xxxyy xxyxx xxyxy xxyyx xxyyy xyxxx xyxxy xyxyx xyxyy xyyxx xyyxy xyyyx xyyyy yxxxx yxxxy yxxyx yxxyy yxyxx yxyxy yxyyx yxyyy yyxxx yyxxy yyxyx yyxyy yyyxx yyyxy yyyyx yyyyy

***32个