int maxRow = 0;
int indexOfMaxRow = 0;
//获取第一行的和
for(int column =0 ;colunmn < matrix[0].length; column++) {
maxRow += matrix[0][column];
}
for(int row = 1;row < matrix.length; row++) {
int totalOfThisRow = 0;
for(int column = 0; column < matrix[row].lengh;column++) {
//循环每行的和
totalOfThisRow += matrix[row][column];
}
//和maxRow作比较
if(totalOfThisRow > maxRow) {
maxRow = totalOfThisRow;
indexOfMaxRow = row;
}
}
获取二维数组各行和的最大值
最新推荐文章于 2023-03-15 21:29:56 发布