我有一个数组错误,说它超出了界限,我不知道出了什么问题。这是我的代码:
import java.util.*;
public class gameVar {
public static int size;
public static int counter;
public static Scanner input = new Scanner(System.in);
public static String currentIn;
public static String nameArray[] = new String[size];
}
和第二类(我在第 6 行得到错误):
public class mainThread extends gameVar {
public static void main(String[] args){
System.out.println("Please type the desired amount of players: ");
size = input.nextInt();
for(int counter = 0; counter < size; counter++){
System.out.println("Please enter the name of player " + nameArray[counter])
}
}
}
非常感谢您的帮助!