简体   繁体   English

创建具有 10 个输入的字符串类型的数组

[英]Creating an Array of type String with 10 inputs

I wanted to practice with array and I don't get why it doesn't print the following out: The problem is that the terminal outputs: null Why is that and what did I do wrong?我想用数组练习,但我不明白为什么它不打印以下内容:问题是终端输出: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]);

    }
}

You are re-assigning women to be an empty string[10] before printing to console.在打印到控制台之前,您正在将 women 重新分配为空字符串 [10]。 Remove women = new String[10];删除women = new String[10]; and it should work fine.它应该工作正常。

String[] women = { "persian", "palestinian", "german", "russian",
"spanish", "italian", "greek", "hungarian","brazilian", "turkish" };

System.out.println(women[8]);

Will work for you.会为你工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM