JAVA编程语言基础第七章课后作业


 		JAVA编程语言基础第七章课后作业
1输入五句话,逆序输出
package tz1;
	import java.util.Scanner;
public class dome24 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.println("请输入5句话");
	String [] word = new String[5];
	for (int i = 0; i < word.length; i++) {
		System.out.print("第"+(i+1)+"句话");
		word[i] = input.next();
	}for (int J = word.length-1;J>=0; J--) {
		
		System.out.println("逆序输入的是"+word[J]);
		
	}
	}
}
2.找出最低分及在数组中的原始位置
package tz1;

import java.util.Arrays;

public class dome25 {
	public static void main(String[] args) {
		int points[] = new int[] { 18, 25, 7, 36, 13, 2, 89, 63 };
		int min = 0;
		int index = points.length;
		min = points[0];
		for (int i = 0; i < points.length; i++) {
			if (min > points[i]) {
				min = points[i];
				index = i;
			}
		}
		System.out.println("最低积分是" + min);

		System.out.println("最低积分的坐标是" + index);
	}

}
3.输入10个整数判断
package tz1;
	import java.util.Scanner;
public class dome26 {
	public static void main(String[] args) {
		int num [] =new int[10];
		int count[] = new int [4];
		System.out.println("请输入10个数");
		Scanner input = new Scanner(System.in);
		for (int i = 0; i < 10; i++) {
			 num[i] = input.nextInt();
		switch (num[i]) {
		case 1:
			count[0]++;
			break;
		case 2:
			count[1]++;
			break;
		case 3:
			count[2]++;
			break;
		default:
			count[3]++;
			break;
		}
		}System.out.println("数字1的个数:"+count[0]);
		System.out.println("数字2的个数:"+count[1]);
		System.out.println("数字3的个数:"+count[2]);
		System.out.println("数字4的个数:"+count[3]);
	}

}
4.在元数组加入新的数组并逆序输出
package tz1;

import java.util.Arrays;

public class dome27 {
	public static void main(String[] args) {
		System.out.println("原数组为");
		int[] array = new int[] {1,3,-1,5,-2};
		int[] array2= new int[5];
		for (int i = 0; i < array.length; i++) {
			System.out.print(array[i]);
		}System.out.println(" ");
		for (int i = array2.length-1,j=0; i>=0; i--,j++) {
			if (!(array[i]<0)) {
				array2[j]=array[i];
			}else {
				continue;
			}
			}System.out.println("逆序后的数组为:");
			for (int i = 0; i < array2.length; i++) {
				System.out.print(array2[i]);
		}
	}
}
5.英文歌曲
package tz1;

import java.util.Scanner;

public class song {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String[] music = new String[] { "Island", "Ocean", "Pretty", "Sun" }; // 原数组
		String[] newMusic = new String[5];
		String name;
		System.out.print("插入前的数组为:");
		for (int i = 0; i < music.length; i++) {
			System.out.print(music[i] + " ");
		}
		for (int i = 0; i < music.length; i++) {
			newMusic[i] = music[i];
		}
		System.out.print("\n请输入歌曲名称:");
		name = input.nextLine();
		int index = newMusic.length;
		for (int j = 0; j < newMusic.length; j++) {
			if (newMusic[j].compareToIgnoreCase(name) > 0) {
				index = j;
				break;
			}
		}
		for (int i = newMusic.length - 1; i > index; i--) {
			newMusic[i] = newMusic[i - 1];
		}
		newMusic[index] = name;
		System.out.print("插入后的数组为:");
		for (int i = 0; i < newMusic.length; i++) {
			System.out.print(newMusic[i] + " ");
		}
	}
}

你可能感兴趣的:(JAVA编程语言基础第七章课后作业)