-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
40 lines (38 loc) · 1.14 KB
/
Main.java
File metadata and controls
40 lines (38 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* 课后练习 5.4
* int[][] a={{1,5,6,81,2},{3,4,5,8,10},{4,6,98,0,43},{22,3,5,12,4}}
* 找出 min max,指出它们所在的行和列
*
* @Author: FoskyM
* @Date: 2023/10/23 20:45
*/
package Work4;
public class Main {
public static void main(String[] args) {
int[][] a = {
{1, 5, 6, 81, 2},
{3, 4, 5, 8, 10},
{4, 6, 98, 0, 43},
{22, 3, 5, 12, 4}
};
int min = a[0][0], max = a[0][0];
int minRow = 0, minCol = 0, maxRow = 0, maxCol = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 5; j++) {
int num = a[i][j];
if (num < min) {
min = num;
minRow = i + 1;
minCol = j + 1;
}
if (num > max) {
max = num;
maxRow = i + 1;
maxCol = j + 1;
}
}
}
System.out.println("min: " + min + " 行: " + minRow + " 列: " + minCol);
System.out.println("max: " + max + " 行: " + maxRow + " 列: " + maxCol);
}
}