public class Main {
public static void main(String[] args) {
int[][] matrix = {
{1, 2, -3, 4, -5},
{5, -1, 6, -2, 7},
{-2, -3, 1, 2, 3},
{0, -1, -2, -3, -4},
};
for (int i = 0; i < matrix.length; i++) {
int firstIndex = -1;
int secondIndex = -1;
for (int j = 0; j < matrix[i].length; j++) {
if (matrix[i][j] > 0) {
if (firstIndex == -1) {
firstIndex = j;
}
else {
secondIndex = j;
break;
}
}
}
if (firstIndex != -1 && secondIndex != -1) {
int sum = 0;
for (int k = firstIndex + 1; k < secondIndex; k++) {
sum = sum + matrix[i][k];
}
System.out.println("Строка " + i + " сумма = " + sum);
} else {
System.out.println("Строка " + i + " — нет двух положительных");
}
}
}
}