标签:generated class fun lse lag Stub ext array iterator
import java.util.HashSet;
import java.util.Set;
public class t {
static Set<Integer> set=new HashSet<Integer>();
static void function (int arr[],int k) {
if(k==4) {
Save(arr);
}
for (int i = k; i < 4; i++) {
int t=arr[k];
arr[k]=arr[i];
arr[i]=t;
function(arr, k+1);
t=arr[k];
arr[k]=arr[i];
arr[i]=t;
}
}
private static void Save(int[] arr) {
// TODO Auto-generated method stub
int iterate=1000;
int x=0;
for (int i = 0; i<4; i++) {
x+=arr[i]*iterate;
iterate/=10;
}
set.add(x);
}
public static void main(String[] args) {
// int arr[]=new int [100];
// arr[0]=9;
// for (int i = 1; i <4; i++) {
// arr[i]=i;
// }
int arr[]= {1,2,3,4};
function(arr, 0);
System.out.println(set.size());
System.out.println(set);
}
}
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class Main {
/*
* 递归全排列框架
*/
static void function (int arr[],int k) {
if(k==4) {
check(arr);
}
for (int i = k; i < 4; i++) {
int t=arr[k];
arr[k]=arr[i];
arr[i]=t;
function(arr, k+1);
t=arr[k];
arr[k]=arr[i];
arr[i]=t;
}
}
static Set<Integer> set =new HashSet<Integer>();
private static void check(int[] arr) {
// TODO Auto-generated method stub
int sum=arr[0]*1000+arr[1]*100+arr[2]*10+arr[3];
Boolean flag=true;
for (int i = 2; i <=Math.sqrt(sum); i++) {
if(sum%i==0)
{
flag=false;
break;
}
}
if(flag==true) {
set.add(sum);
}
}
public static void main(String[] args) {
int arr[]= {1,9,4,9};
function(arr,0);
System.out.println(set.size());
System.out.println(set);
Iterator<Integer> iterator=set.iterator();
while(iterator.hasNext()) {
int xx=iterator.next();
System.out.print(xx+" ");
}
}
}
6
[4919, 9941, 9491, 1949, 9419, 1499]
标签:generated class fun lse lag Stub ext array iterator
原文地址:https://www.cnblogs.com/effortfordream/p/12722039.html