我想练习数组,但我不明白为什么它不打印以下内容: 问题是终端输出:null 这是为什么?我做错了什么?
package Practice;
public class CreatingArrays {
public static void main(String[] args) {
String[] women = { "persian", "palestinian", "german", "russian", "spanish", "italian", "greek", "hungarian",
"brazilian", "turkish" };
women = new String[10];
System.out.println(women[8]);
}
}
在打印到控制台之前,您正在将 Women 重新分配为空字符串 [10]。 删除
women = new String[10];
,它应该可以正常工作。
String[] women = { "persian", "palestinian", "german", "russian",
"spanish", "italian", "greek", "hungarian","brazilian", "turkish" };
System.out.println(women[8]);
将为您工作。
公共类创建数组{ 公共静态无效主(字符串[] args){
String[] women = { "persian", "palestinian", "german", "russian", "spanish", "italian", "greek", "hungarian",
"brazilian", "turkish" };
System.out.println(women[8]);
}
}