Java求馬鞍點(行中最大,列中最小)
public class maandian {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[][] a = { { 5, 25, 10, 12 }, { 1, 6, 7, 5 }, { 2, 7, 8, 6 } };
int max[][] = new int[3][2];
int min[][] = new int[4][2];
// System.out.print(a[0][0]);
for (int i = 0; i < 3; i++) {
// System.out.println(a[i][0]+"");
// System.out.print(max[i]);
max[i][0] = a[i][0];
max[i][1] = 0;
for (int j = 1; j < 4; j++) {
if (a[i][j] > max[i][0]) {
max[i][0] = a[i][j];
max[i][1] = i;
// System.out.println(max[i][0]);
}
}
}
for (int j = 0; j < 4; j++) {
min[j][0] = a[0][j];
for (int i = 1; i < 3; i++) {
if (a[i][j] < min[j][0]) {
min[j][0] = a[i][j];
min[j][1] = j;
}
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
if (max[i][0] == min[j][0]) {
System.out.print("馬鞍點位置:第" + (max[i][1]+1) + "行 第" + (min[j][1]+1)
+ "列。值為" + max[i][0]);
}
}
}
}
}