import java.util.Arrays;
import java.util.Scanner;
public class Shuju2 {
public static void main(String[] args) {
char[] letter = new char[9];
letter[0] = 'a';
letter[1] = 'b';
letter[2] = 'c';
letter[3] = 'e';
letter[4] = 'f';
letter[5] = 'p';
letter[6] = 'u';
letter[7] = 'z';
System.out.print("原字符序列:");
for (int i=0;i<letter.length;i++) {
System.out.print(letter[i] +"\t");
}
int letter1 = letter.length;//保存新增字母插入位置
char num ='d';
System.out.println("\n新插入的字符是:" +num);
for (int b=0;b<letter.length;b++) {
if (num<letter[b]) {
letter1 = b;
break;
}
}
for (int k=letter.length-1;k>letter1;k--) {
letter[k] = letter[k-1];//letter下标开始的元素后移动一个位置
}
letter[letter1] = num;
System.out.print("插入成绩的下标是:" + letter1);
System.out.print("\n插入后的字符序列是:");
for (int g=0;g<letter.length;g++) {
System.out.print(letter[g] +"\t");
}
}
}
第七章数组
最新推荐文章于 2018-12-14 22:15:46 发布