import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.Random;
public class Test2 {
public static void add(int n,int l){
String str = "qwertyuiopasdfghjklzxcvbnmQWERRTYUIOPASDFGHJKLZXCVBNM1234567890";
List<String> a=new ArrayList<String>();
Random c=new Random();
for(int i=0;i<n;){
int d=c.nextInt(l)+1;
StringBuilder t=new StringBuilder();
for(int num=0;num<d;){
int e=c.nextInt(str.length());
//if(t.toString().indexOf(str.charAt(e))==-1){
t.append(str.charAt(e));
num++;
//}
}
if(a.contains(t.toString())){
continue;
}else{
a.add(t.toString());
i++;
}
}
for(String f:a){
System.out.print(f+" ");
}
System.out.println();
Collections.sort(a);
for(String f:a){
System.out.print(f+" ");
}
}
public static void main(String[] args) {
add(10,10);
}
}
共同学习,写下你的评论
评论加载中...
作者其他优质文章