矩阵中列的最大值?

时间:2013-03-19 17:57:23

标签: for-loop matrix max

如何在Java中仅使用2 for for?找到矩阵中列的最大值?

for(int i = 1; i< N; i++)
    for(int j = 1; j < M; j++)
         i want to find the maxim for each column

1 个答案:

答案 0 :(得分:1)

public int findMaxInCol(int colIndex){
  int max = Integer.Min;
  for(int row=0;row<Matrix.Rows;row++){

    if(matrix[row][colIndex] > max){
       max = matrix[row]colIndex];
   }

}
   return max;
}



void int findMaxOfMaxes() {
   int maxOfMaxs = Integer.min;
   for(int col=0;col<j;col++){
      int maxInCol = findMaxInCol(col);
      if( maxInCol > maxOfMaxs)
          maxOfMaxs = maxInCol;
    }
    return maxOfMaxs 

} 

//伪代码

//在找到矩阵中的最大值后进行编辑。你是对的,你需要2个循环。

相关问题