public class Test10 {
//需要排列的字符串
static String string = "ming";
//记录上一次排列中的所有的组合
static List<String> list = new ArrayList<String>();
//临时的数组,用于比较
static List<String> temp = new ArrayList<String>();
public static void main(String[] args) {
init();
printList(list);
if (string.length() > 1) {
int index = 2;
//排序的大小,最多为字符串的长度
while (index <= string.length()) {
for (int i = 0; i < list.size(); i++) {
for (int j = 0; j < string.length(); j++) {
public class Test24
{
public static void main(String[] args)
{
String test = "abc";
TreeSet<String> set = new TreeSet<String>();
method(test, set);
for (int i = 1; i <= test.length(); i++)
{
for (String s : set)
{
if (s.length() == i)
System.out.print("\"" + s + "\"" + "\t");
}
System.out.println();
}
}
public static void method(String test, TreeSet<String> set)
{
for (int x = 0; x < test.length(); x++)
{
test.charAt(x);
String ssss = test.charAt(x) + "";
set.add(ssss);
for (int y = 0; y < test.length(); y++)
{
if (y == x)
continue;
test.charAt(y);
String sss = test.charAt(x) + "" + test.charAt(y);
set.add(sss);
for (int z = 0; z < test.length(); z++)
{
if (z == x || z == y)
continue;
test.charAt(z);
String ss = test.charAt(x) + "" + test.charAt(y) + test.charAt(z);
set.add(ss);
}
}
}
}
}
作者: java_dream 时间: 2014-10-25 23:55
package test;
import java.util.Random;
/**
* 编程列出一个字符串的全字符组合情况,原始字符串中没有重复字符,例如(这只是个特例):
* 原始字符串是"abc",打印得到下列所有组合情况:
* "a" "b" "c"
* "ab" "bc" "ca" "ba" "cb" "ac"
* "abc" "acb" "bac" "bca" "cab" "cba"
*
* @author live-dream
*
*/
public class Test003 {
public static void main(String[] args) {
String s = "abcde";
int n = s.length();
for(int i=1; i<=n; i++){
int[][] permutations = permutationResults(n,i);
for(int j=0; j<permutations.length; j++){
print(s,permutations[j]);
}
System.out.println();
}
}
public static int[][] permutationResults(int n,int r){