GetValueAt(Int a, int b) which returns int



我有一个数组[]的映射,我有一种方法

public int[][] getMap(){
int [][] array = new int[this.size][this.size];
for(int i=0;i<this.map.length;i++)
{
for(int j=0;j<this.map[i].length;j++)
{
array[i][j]=map[j][i];
}
}
return array;
}

现在我需要重写上面的代码,只使用

public int getValueAt(int a, int b){}

我不太明白你想要实现什么,但我认为你想做到这一点:

public int getValueAt(int a, int b){
return this.map[a][b]
}

然后你可以使用这种方法:

public int[][] getTransformedCopy() {
int[][] array = new int[this.map.length][this.map[0].length]
for(int i = 0; i < this.map.length; i++) {
for(int j = 0; j < this.map[0].length; j++) {
array[i][j] = getValueAt(j, i);
}
}
return array;
}

最新更新