package main.test;
import java.util.*;
import java.lang.*;
class Main05{
//5、要求:随机打印50个随机(4-10长度)的字符串,要求字符串包含的范围是所有的英文字母包含大小写和数字,按照编码顺序排序,每行打印4个,要求首字符对齐
public static void main(String[] args){
String str = new String("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
List<StringBuffer> list=new ArrayList<StringBuffer>();
Random random=new Random();
for(int i=0;i<10;i++){
int leng=(int)(random.nextInt(7)+4);
StringBuffer sb=new StringBuffer();
for(int z=0;z<leng;z++){
int num=random.nextInt(62);
sb.append(str.charAt(num));
}
list.add(sb);
}
for(int x=0;x<list.size();x++){
for(int i=0;i<list.size()-1-x;i++){
char[] ch1=list.get(i).toString().toCharArray();
char[] ch2=list.get(i+1).toString().toCharArray();
if(ch1.length>=ch2.length){
for(int j=0;j<ch2.length-1;j++){
if(ch1[j]>ch2[j]){
StringBuffer temp=list.get(i+1);
list.set(i+1,list.get(i));
list.set(i,temp);
break;
}else if(ch1[j]<ch2[j]){
break;
}
}
}else{
for(int h=0;h<ch1.length;h++){
if(ch1[h]>ch2[h]){
StringBuffer temp=list.get(i+1);
list.set(i+1,list.get(i));
list.set(i,temp);
break;
}else if(ch1[h]<ch2[h]){
break;
}
}
}
}}
print(list);
}
private static void print(List<StringBuffer> list)
{
for (int i = 0; i < list.size(); i++)
{
StringBuffer s = list.get(i);
System.out.print(s);
// 字符串不满10个用空格填充
for (int j = 0; j <= 10 - s.length(); j++)
{
System.out.print(" ");
}
// 四个字符串一行
if ((i + 1) % 4 == 0)
{
System.out.println("\n");
}
}
}
}