嗨,伙计们,一个快速的问题。我在下面创建一个 Java 菜单是一段代码示例。我想知道我是否在“if”语句中设置了 2 个数组,如何再次引用这些数组。我知道由于范围的原因,当移出 if 语句时,数组会被破坏。如果选择了选项 P,我想再次引用数组。
public static void determineOption (char option) {
if (option == 'A') {
int class_number = Console.getInt("Enter how many students between 1-10");
while (class_number < 1 || class_number > 10)
class_number = Console.getInt("Enter how many students between 1-10");
System.out.println("");
String[] name = new String[class_number];
int[] score = new int[name.length];
for (int i=0; i<class_number; i=i+1)
{
name[i] = Console.getString("Enter Name");
score[i] = Console.getInt("Enter score");
}
}
else if (option == 'P') {
}