-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject23.java
More file actions
44 lines (37 loc) · 1.23 KB
/
Project23.java
File metadata and controls
44 lines (37 loc) · 1.23 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
41
42
43
44
import java.util.Scanner;
public class Project23 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the size of the square matrix (n): ");
int n = sc.nextInt();
int[][] matrix = new int[n][n];
System.out.println("Enter the elements of the " + n + "x" + n + " matrix row-wise:");
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
matrix[i][j] = sc.nextInt();
}
}
for (int i = 0; i < n; i++) {
int minCol = 0;
for (int j = 1; j < n; j++) {
if (matrix[i][j] < matrix[i][minCol]) {
minCol = j;
}
}
boolean isSaddle = true;
for (int k = 0; k < n; k++) {
if (matrix[k][minCol] > matrix[i][minCol]) {
isSaddle = false;
break;
}
}
if (isSaddle) {
System.out.println("Saddle Price: " + matrix[i][minCol]);
sc.close();
return;
}
}
System.out.println("No Saddle Price Found");
sc.close();
}
}