62,636
社区成员




public class ChuHe {
public static void main(String[] args) {
int[] a = { 2, 4, 7, 9 };
int[] b = new int[4];
for (int i = 0; i < a.length; i++) {
b[0] = a[i];
for (int j = 0; j < a.length; j++) {
b[1] = a[j];
for (int k = 0; k < a.length; k++) {
b[2] = a[k];
for (int m = 0; m < a.length; m++) {
b[3] = a[m];
if (i != j && i != k && i != m && j != k && j != m
& k != m) {
for (int p = 0; p < b.length; p++) {
System.out.print(b[p]);
}
System.out.println();
}
}
}
}
}
}
}
public class ArrayCombination {
static int[] a = {1, 2, 3};
static int count = 0;
public static void main(String[] args) {
permutation(0, a.length-1);
System.out.println("一共有" + count + "种组合");
}
public static void permutation(int m, int n) {
int i;
if (m == n) {
display(a);
count++;
}
for (i = m; i <= n; i++) {
swap(i,m);
permutation(m + 1, n);
swap(i,m);
}
}
public static void display(int[] array) {
for (int i = 0; i < array.length; i++) {
System.out.print(array[i]);
}
System.out.println();
}
public static void swap(int x,int y){
int temp = a[x];
a[x] = a[y];
a[y] = temp;
}
}
public class Test2 {
char[] d=null;
int p=-1;
public static void main(String[] args) {
new Test2().permute("2367");
}
public void permute(String str) {
d=new char[str.length()];
permute(str.toCharArray(),0, str.length()-1);
}
public void permute(char[] str, int low, int high) {
if(low>high){
System.out.println(new String(d,0,p+1));
return;
}
p++;
for(int i=low;i<=high;i++) {
char a=str[i];
str[i]=str[low];
str[low]=a;
d[p]=str[low];
permute(str,low+1, high);
char b=str[i];
str[i]=str[low];
str[low]=b;
}
p--;
}
}
public static void swap(int x,int y){
int temp = a[x];
a[x] = a[y];
a[y] = temp;
}
public class ArrayCombination {
static int a[] = {1,2,3,4};
static void permutation(int m,int n)
{
int i;
if(m==n)
{
for(i = 0;i<=n;i++)
{
print(a[i]);
}
print("\n");
}
for(i = m;i<=n;i++)
{
int t=a[i];a[i]=a[m];a[m]=t;
permutation(m+1,n);
t=a[i];a[i]=a[m];a[m]=t;
}
}
public static void print(Object o) {
System.out.print(o.toString());
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
permutation(0,3);
}
}