なぜminRowとminRowIndexの値が0になるのですか?お返事いただきありがとうございます。2D配列の最小合計を持つ行を見つけようとしましたが、0しか取得しません
import java.util.Scanner;
public class test1 {
public static void main(String[] arg) {
Scanner in = new Scanner(System.in);
int [][] matrix = {{1, 2, 3, 4, 5}, {2, 3, 4, 5, 6}, {3, 4, 5, 6, 7}};
int minRow = 0;
int minRowAvg = 0;
int minRowIndex = 0;
for (int row = 1; row < matrix.length; row++){
int rowSum = 0;
for (int col = 0; col < matrix[row].length; col++){
rowSum += matrix[row][col];
}
if (rowSum < minRow && rowSum > 0){
minRow = rowSum;
minRowIndex = row;
}
}
System.out.println("Row " + minRowIndex + " has the minimum sum of " + minRow);
}
}
コードにはより多くの書式設定が必要です – Dbz