标题:Java输出字符串的全排列
public class TestAllSort {
public void allSort(String s
, int count
, int[] a
) {
if(count
>= 4) {
System
.out
.println();
return ;
}else {
for(int i
= 0; i
< 4; i
++) {
if(a
[i
] != -1) {
System
.out
.print(s
.charAt(i
) + "");
a
[i
] = -1;
this.allSort(s
, count
+ 1, a
);
a
[i
] = 0;
}
}
}
}
@Test
public void test() {
String s
= "ABCD";
int count
= 0;
int[] a
= new int[s
.length()];
}
public void allSort02(String s
, int count
, char[] a
) {
if(count
>= 4) {
for(int i
= 0; i
< a
.length
; i
++) {
System
.out
.print(a
[i
]);
}
System
.out
.println();
return ;
}else {
for(int i
= 0; i
< 4; i
++) {
if(a
[i
] == 0) {
a
[count
] = s
.charAt(i
);
this.allSort02(s
, count
+ 1, a
);
a
[count
] = 0;
}
}
}
}
@Test
public void test02() {
String s
= "ABCD";
int count
= 0;
char[] a
= new char[s
.length()];
char ch
= '0';
int b
= ch
;
}
public void allSort03(String s
, int count
, int[] a
) {
if(count
>= 4) {
for(int i
= 0; i
< a
.length
; i
++) {
System
.out
.print(s
.charAt(a
[i
]));
}
System
.out
.println();
return ;
}else {
for(int i
= 0; i
< a
.length
; i
++) {
if(a
[i
] == -1) {
a
[i
] = count
;
this.allSort03(s
, count
+ 1, a
);
a
[i
] = -1;
}
}
}
}
@Test
public void test03() {
String s
= "ABCD";
int count
= 0;
int[] a
= new int[s
.length()];
Arrays
.fill(a
, -1);
this.allSort03(s
, count
, a
);
}
}
转载请注明原文地址: https://lol.8miu.com/read-36627.html