import java.util.Arrays;
public class Day15 {
//数组
//题目1:
//创建一个长度是8的字符串数组,使用8个长度是5的随机字符串初始化这个数组 对这个数组进行排序,按照每个字符串的首字母排序(无视大小写)
//注1: 不能使用Arrays.sort() 要自己写
//注2: 无视大小写,即 Axxxx 和 axxxxx 没有先后顺序
public static void main(String[] args) {
String []str = new String[8];
for(int i =0;i<str.length;i++){
str[i]= makeStr();
}
System.out.println("排序前"+ Arrays.toString(str));
for (int j = 0; j < str.length; j++) {
for (int i = 0; i < str.length - j - 1; i++) {
char firstChar1 = str[i].charAt(0);
char firstChar2 = str[i + 1].charAt(0);
firstChar1 = Character.toLowerCase(firstChar1);
firstChar2 = Character.toLowerCase(firstChar2);
if (firstChar1 > firstChar2) {
String temp = str[i];
str[i] = str[i + 1];
str[i + 1] = temp;
}
}
}
System.out.println("排序后"+Arrays.toString(str));
}
public static String makeStr(){
String pool = "";
for (short i = '0'; i <= '9'; i++) {
pool+=(char)i;
}
for (short i = 'a'; i <= 'z'; i++) {
pool+=(char)i;
}
for (short i = 'A'; i <= 'Z'; i++) {
pool+=(char)i;
}
char cs2[] = new char[5];
for (int i = 0; i < cs2.length; i++) {
int index = (int) (Math.random()*pool.length());
cs2[i] = pool.charAt( index );
}
String result2 = new String(cs2);
return result2;
}
}