在我們編程時
一
所謂全排列
二
所謂組合
下面是我們的Java源程序
mytest
package customers;
public class mytest
{String[] mychar=new String[
int charcount;
int charlist;
public void SetMyTest()
//初始化
{charcount=
charlist=
}
public void insertChar(String thischar)
//增加新的字符串
{charcount++;
mychar[charcount]=thischar;
charlist*=charcount;
}
public String listAllChar()
//列出全排列
{String[][] allchar=new String[charlist+
int i;
int j;
int z=
for (i=
{myCopy(addCharList(i
z*=i;
}
String listallchar=new String(\
for (i=
{for (j=
listallchar+=allchar[i][j]+\
listallchar=listallchar+\
}
return listallchar;
}
public String[][] addCharList(int i
//在i
{int j;
int h=
int k;
String[][] tempallchar=new String[charlist+
for (k=
{for (j=
{myCopy(tempchar(j
h++;
}
}
return tempallchar;
}
public String[] tempchar(int i
//將新對象插入指定位置
{int j;
String[] tempbeginchar=new String[charcount+
myCopy(beginchar
for (j=charcount;j>i;j
tempbeginchar[i]=thischar;
return tempbeginchar;
}
public String selectSomeChar(int select)
//列出其中取出select個對象的全部組合
{int selectcount=
int i;
for (i=select+
String[][] selectchar=new String[selectcount+
int[][] selectint=new int[selectcount+
for (i=
{selectchar[
selectint[
}
int z=
addSelect(selectchar
int j;
String selectsomechar=new String(\
for (i=
{for (j=
selectsomechar+=selectchar[i][j]+\
selectsomechar=selectsomechar+\
}
return selectsomechar;
}
public void addSelect(String[][] selectchar
//增加新的組合
{int i;
if (position==select)
{if (selectint[z][position]<charcount)
{z++;
myCopy(selectint[z
selectint[z][select]++;
for (i=
addSelect(selectchar
}
else
{position
addSelect(selectchar
}
}
else
{if (selectint[z][position]<charcount
{selectint[z][position]++;
selectint[z][position+
position++;
addSelect(selectchar
}
else
{if (position==
{return;
}
else
{position
addSelect(selectchar
}
}
}
}
public void myCopy(String[][] Str
{int h;
int k;
for (h=
}
public void myCopy(String[] Str
{int h;
for (h=
}
public void myCopy(int[] Str
{int h;
for (h=
}
}
現在我們可以在一個JSP程序中使用這個JavaBean
<%@ page contentType=\
<HTML>
<HEAD>
<TITLE>
排列和組合
</TITLE>
</HEAD>
<BODY>
<jsp:useBean id=\
<%
mytest
mytest
mytest
mytest
mytest
mytest
mytest
out
out
%>
</BODY>
</HTML>
三
所謂排列
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26258.html