public static void main(String[] args) {
char[] chars = new char[9];
chars[0] = 'a';
chars[1] = 'c';
chars[2] = 'u';
chars[3] = 'b';
chars[4] = 'e';
chars[5] = 'p';
chars[6] = 'f';
chars[7] = 'z';
System.out.print("原字符序列:");
System.out.println(Arrays.toString(chars));
for (int i = 0; i < chars.length-1; i++) {
for (int j = 0; j < chars.length-i-1; j++) {
if (chars[j] > chars[j+1]) {
char k = chars[j+1];
chars[j+1] = chars[j];
chars[j] = k;
}
}
}
System.out.print("\n升序排序后:");
System.out.println(Arrays.toString(chars));
int index = chars.length;
char ch='m';
for(int i = 0; i < chars.length; i++){
if(ch < chars[i]){
index = i;
break;
}
}
for(int j = 0; j < index; j++){
chars[j] = chars[j+1];
}
chars[index] = ch;
System.out.print("\n插入数据排序后:");
System.out.println(Arrays.toString(chars));
}