我有以下代码:
public class PlayerName {
public void playerName(){
int []playerNames = new int[playerNames[[n]];
for(int n=0; n<=playerNames[n];n++){
playerNames[n] = Helper.readInt("Enter no of players playing: " );
}
}
}
我一直在尝试根据用户输入初始化一个数组,但他们说我必须创建一个名为n
的局部变量。
答案 0 :(得分:1)
你必须先设置它才能像这样
public class PlayerName {
public void playerName(){
int x = Helper.readInt("Enter the dynamic For Value: ");
int []playerNames = new int[playerNames[[x]];
for(int n=0; n<x;n++){
playerNames[n] = Helper.readInt("Enter no of players playing: " );
}
}
}