假设这是我的代码: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循环中确定的所有值之前初始化数组,以便我可以将它用于我的程序的其余部分。
1 回答
潇湘沐
TA贡献1816条经验 获得超6个赞
写信给它:
public class Test {
public static void main(String[] args) {
int[] text = new int[example.length()];
for (int i = 0; i < example.length(); i++) {
text[i] = maybe.indexOf(example);
}
}
}
text[i]写入ith+1数组中的位置(C 样式数组从 0 开始计数 - 出于涉及内存引用位置的复杂原因)。
添加回答
举报
0/150
提交
取消