1.首先依次输入五句话,然后将它逆序输出:
import java.util.Scanner;
public class Array {
public static void main(String[] args) {
// InteGral();
//LegitimateUalue();
String [] speak = new String [5]; //数组长度
System.out.println("请输入5句话");
Scanner input = new Scanner(System.in);
for (int i = 0; i < speak.length; i++) {
System.out.print("第"+(i+1)+"句话:");
speak[i] = input.next();
}
System.out.println("\n逆序输出5句话为:");
for (int i = speak.length-1;i>=0; i--) {
System.out.println(speak[i]);
}
}
2.
public static void InteGral() {
int [] points = {18,25,7,36,13,2,89,63};
int min =points[0]; int index =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.
public static void LegitimateUalue() {
int [] nums = new int [10];
int [] count = new int [4];
System.out.println("请输入10个数");
Scanner input = new Scanner(System.in);
for (int i = 0; i < nums.length; i++) {
nums[i] = input.nextInt();
switch(nums[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("非法数字个数:"+count[3]);
}
}
4.
import java.util.Scanner;
public class Array1 {
public static void main(String[] args) {
int [] array = new int [] {1,3,-1,5,-2};
System.out.println("原数为:");
for (int i = 0; i < array.length; i++) {
System.out.print(array[i]+" ");
}
System.out.println("\n逆序并处理输出数组为:");
for (int j = array.length-1;j >=0; j--) {
if(array[j]<0) {
array[j] =0;
}
System.out.print(array[j]+" ");
}
// Cx();
}
5.
public static void Cx(){
String [] music = new String [] {"IsLand","Ocean","Pretty","Sun"};
String [] music1 = new String [5];
System.out.print("插入前的数组为:");
for (int i = 0; i < music.length; i++) {
System.out.print(" "+music[i]);
music1 [i] = music[i];
}
int index = 0;
Scanner input = new Scanner(System.in);
System.out.print("\n请输入歌曲名称:");
String num = input.next();
for (int i = 0; i < music1.length; i++) {
if(music1[i].compareToIgnoreCase(num)>0) {
index = i;
break;
}
}
for (int i = music1.length-1;i >index; i--) {
music1[i] = music1[i-1];
}music1[index]=num;
System.out.println("插入后的下标:"+index);
System.out.print("插入后的数组为:");
for (int k = 0; k < music1.length; k++) {
System.out.print(music1[k]+" ");
}
}
}