我在for循环之前声明了数组,现在我想将for循环的结果连接到数组中。以下不起作用,并给我错误为“错误:无法找到符号”。在java中连接数组中循环的结果
我的代码是
for(int j=i; j<=arr.length-1; j++){
// checking for condition
if (i<j)
{
int temp = arr[i]+arr[j];
if (temp%sum==0) {
System.out.println("Pair with given sum " +
sum + " is (" +temp+")");
result[] += temp;
}
}
对不起,我忘了在福尔循环包括,谈到之前的if语句 – aditya
'结果[] + = temp'显然是不正确。这个数组最初是在哪里申报的? – Makoto
声明结果[]数组并将temp插入数组的某个索引。 例如result [i] = temp。如果您不知道结果数组的最终大小,您可以使用arraylist。 – Gihanmu