package Homework;
import java.util.Scanner;
public class L7H{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
String[] musics=new String[]{"Island","Ocean","Pretty","Sun"};
String[] nummusics=new String[musics.length+1];
int index=0;
String music="";
System.out.print("插入前的数组:");
for(int i=0;i<musics.length;i++){
nummusics[i]=musics[i];
}
for(int i=0;i<musics.length;i++){
System.out.print(musics[i]+" ");
}
System.out.println("");
System.out.print("请输入新的单词");
music=input.nextLine();
System.out.print("插入前新单词的下标:");
for(int i=0;i<nummusics.length;i++){
if(nummusics[i].compareTo(music)>0){
index=i;
break;
}
}
System.out.println(index);
for(int i=nummusics.length-1;i>index;i--){
nummusics[i]=nummusics[i-1];
}
nummusics[index]=music;
System.out.print("插入后的数组:");
for(int i=0;i<nummusics.length;i++){
System.out.print(nummusics[i]+" ");
}
}
}
import java.util.Scanner;
public class L7H{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
String[] musics=new String[]{"Island","Ocean","Pretty","Sun"};
String[] nummusics=new String[musics.length+1];
int index=0;
String music="";
System.out.print("插入前的数组:");
for(int i=0;i<musics.length;i++){
nummusics[i]=musics[i];
}
for(int i=0;i<musics.length;i++){
System.out.print(musics[i]+" ");
}
System.out.println("");
System.out.print("请输入新的单词");
music=input.nextLine();
System.out.print("插入前新单词的下标:");
for(int i=0;i<nummusics.length;i++){
if(nummusics[i].compareTo(music)>0){
index=i;
break;
}
}
System.out.println(index);
for(int i=nummusics.length-1;i>index;i--){
nummusics[i]=nummusics[i-1];
}
nummusics[index]=music;
System.out.print("插入后的数组:");
for(int i=0;i<nummusics.length;i++){
System.out.print(nummusics[i]+" ");
}
}
}