private static void method11() {
Scanner sc = new Scanner(System.in);
String[] names = new String[3];
String answer;
int index = 0;
do {
System.out.println("请录入姓名: ");
if (index >= names.length) {
//对数组进行扩容,让names指向新的数组
System.out.println("数组要扩容了");
// names指向新的数组,names是个引用 其中存储的是某块内存的起始地址
names = Arrays.copyOf(names, names.length * 2);
}
names[index] = sc.next();
index = index + 1;
System.out.println("是否继续 Y/N");
answer = sc.next();
} while (answer.equals("y"));
System.out.println(Arrays.toString(names));
System.out.println("程序结束");
}