我有以下方法应该返回31行的数组(每行有31个索引)。这是我的代码:
public static int[] funcA (int[] arrayB,int[] arrayC){
int d,i;
int [] arrayA = new int[31];
int [] arrayD= new int[31];
for (d=0; d<31; d++){
int []temp = new int[31];
for (i=0; i<31; i++){
arrayA [i] = arrayB[i] ^ arrayC[i];
}
// at this point, 31 values are generated inside the arrayA.
// my problem is here: the 31 values of arrayA should be assigned to arrayD in row[d](the row has 31 indexes)
// then, an operation occur to arrayC and the values of arrayA are changed
}
return arrayD;
}
怎么做?如何创建具有两个维度的arrayD并在每次arrayA更改时将31个值(arrayA)传递给单行(31个索引)(总之,我想在arrayD中存储arrayA的'history',因此D中的每一行代表A)的不同状态?
答案 0 :(得分:3)
使i
公共变量的初始值为0
private void copy(int[] arrayA, int[][] arrayD) {
int copySize = arrayA.length;
System.arraycopy(arrayA, 0, arrayD[i], 0, copySize);
// i should increment every time the 'history' is stored in arrayD
i++;
}