先前初始化后如何使用数组(并为其赋值)?

假设这是我的代码:


public class Test {

    public static void main(String[] args) { 

        int[] text = new int[0];

        for (int i = 0; v<example.length(); i++) {

            int text[] = {maybe.indexOf(example)

        };

    }

}

我怎么能让for循环内的数组只是覆盖text[]在它之前初始化的数组?现在我收到错误消息,Javatext3在我的for循环中找不到符号。我想text[]在它具有for循环中确定的所有值之前初始化数组,以便我可以将它用于我的程序的其余部分。


慕标5832272
浏览 160回答 1
1回答

潇湘沐

写信给它:public class Test {&nbsp; &nbsp; public static void main(String[] args) {&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; int[] text = new int[example.length()];&nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i < example.length(); i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text[i] = maybe.indexOf(example);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}text[i]写入ith+1数组中的位置(C 样式数组从 0 开始计数 - 出于涉及内存引用位置的复杂原因)。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java