关闭

第九章练习

标签: classstringsun
418人阅读 评论(0) 收藏 举报
package cn.jiit.test.day9;

import java.util.Scanner;

public class test1 {
	public static void main(String[] args) {
		
		String[] musics = new String[] { "Island", "Ocean", "Pretty", "Sun" };
		String[] newMusics = new String[musics.length + 1];
		String music = "";
		int index = musics.length;
		System.out.println("插入前的数组为:");
		for (int i = 0; i < musics.length; i++) {
			System.out.println(musics[i] + " ");
		}
		for (int i = 0; i < musics.length; i++) {
			newMusics[i] = musics[i];
		}
		Scanner input = new Scanner(System.in);
		System.out.println("请输入歌曲名字");
		music = input.next();
		for (int i = 0; i < musics.length; i++) {
			if (musics[i].compareToIgnoreCase(music) > 0) {// ????
				index = i;
				break;
			}
		}
		for (int i = newMusics.length - 1; i > index; i--) {
			newMusics[i] = newMusics[i - 1];
		}
		newMusics[index] = music;
		System.out.println("插入后的数组为:");
		for (int i = 0; i < newMusics.length; i++) {
			System.out.println(newMusics[i] + " ");
		}
	}
}


 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:16605次
    • 积分:411
    • 等级:
    • 排名:千里之外
    • 原创:25篇
    • 转载:0篇
    • 译文:0篇
    • 评论:11条
    文章存档
    最新评论