# 求所有4(5,6...)字母的组合,求高手赐教.高分

dd121011 2015-06-02 10:01:29

26个英文字母,所有四字母的组合
aaaa
abcd
abce
.....
wxyz
zzzz
...全文
130 3 打赏 收藏 举报

3 条回复

• 打赏
• 举报

0-25 分别代表a-z 上面的26改为25，不是从1开始计数的...

• 打赏
• 举报

``````
public class Com {
static char[] characters = {'a','b','c','d','e','f','g','h','i',
'j','k','l','m','n','o','p','q','r',
's','t','u','v','w','x','y','z'};
static int num = 5;
static int count = 0;
//脚标数组
static int[] a = new int[num];
public static void increaseByOne(){
a[num-1]++;
count++;
for (int i = a.length - 1 ; i > 0 ; i--) {
if(a[i]>26)
{
a[i-1]++;
a[i] = 0;
}
}
setArray();
}

public static void setArray(){
for (int i = 1; i < a.length; i++) {
for (int j =0 ; j < i; j++) {
if (a[j] > a[i]) {
a[i] = a[j];
}
}
}
}

public static void printA()
{
for (int i = 0; i < a.length; i++) {
System.out.print(a[i]+",");
}
System.out.println();

}
public static void main(String[] args) {
printA();
while(a[0] <= 26)
{
increaseByOne();
printA();
}
System.out.println("一共"+(count+1)+"组合");
}
}
``````
dd121011 2015-06-03
• 打赏
• 举报

4.9w+

Java相关技术讨论
javaspring bootspring cloud 技术论坛（原bbs）

2015-06-02 10:01