import java.util.Scanner;
public class a1 {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5};
System.out.print("此时数组为 ");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
Scanner myScanner = new Scanner(System.in);
label:
do {
if (arr.length == 1) {
System.out.println("不能再缩减");
break;
}
do {
System.out.println("是否对数组缩减 y/n");
char choose = myScanner.next().charAt(0);
if (choose == 'y') {
int[] arrNew = new int[arr.length - 1];
for (int i = 0; i < arrNew.length; i++) {
arrNew[i] = arr[i];
}
arr = arrNew;
System.out.print("缩减后的数组为 ");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
break;
} else if (choose == 'n') {
System.out.println("退出");
break label;
} else {
System.out.println("输入错误,请重新输入");
}
}while (true);
}while (true);
System.out.println("程序结束");
}
}
|