0

Javaでforを2つだけ使用して、マトリックス内の列の最大値を見つけるにはどうすればよいですか?

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

1 に答える 1

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 つの for ループが必要です。

于 2013-03-19T18:00:18.570 に答える