解题思路:
注意事项:
参考代码:
public class Test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] [] arr = new int[5][5];
for (int i = 0;i<5;i++) {
for (int j = 0;j<5;j++) {
arr[i][j] = scanner.nextInt();
}
}
int [] maxRow = new int[5];//存放每行的最大值
int index1 = 0;
int [] minCol = new int[5];//存放每列的最小值
int index2 = 0;
int row = 0;
int col = 0;
for (int i = 0;i<5;i++) {
row = 0;
col = Integer.MAX_VALUE;
for (int j = 0;j<5;j++) {
row = Math.max(row, arr[i][j]);//找出每行最大的值
col = Math.min(col, arr[j][i]);//找出每列最小的值
}
maxRow[index1++] = row;//将每行的最大值添加到数组中
minCol[index2++] = col;//将每列的最小值添加到数组中
}
boolean isExit = false; //是否有鞍点
for (int i = 0;i<5;i++) {
for (int j = 0;j<5;j++) {
if (maxRow[i] == minCol[j]) {
isExit = true;
System.out.printf("%d %d %d\n", i+1,j+1, maxRow[i]);
}
}
}
if (!isExit) System.out.println("not found");
}
}
0.0分
0 人评分