import java.util.Scanner;
public class Eext {
public static void main(String[] args) {
Scanner myscanner = new Scanner(System.in);
//用户输入扩容
//数组扩容
int[] arr = {1,2,3};
do {
int[] arr2 = new int[arr.length + 1]; //定义了一个 arr容量加一 的数组
for (int i = 0; i < arr.length; i++) {
arr2[i] = arr[i]; //将arr的值 赋给arr2
}
System.out.println("请输入需要添加的元素:");
int num = myscanner.nextInt();
arr2[arr2.length - 1] = num; //把 num 赋给 arr2 的最后一个元素
arr = arr2; //让arr 指向 arr2
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + "\t"); //遍历arr
}
System.out.println("请问是否还需要输入? y/n");
int key = myscanner.next().charAt(0);
if (key == 'n') {
System.out.println("已退出");
break;
}
}while (true);
}
}