-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaddlePoint.java
More file actions
50 lines (48 loc) · 1.42 KB
/
Copy pathSaddlePoint.java
File metadata and controls
50 lines (48 loc) · 1.42 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
45
46
47
48
49
50
package basic;
import java.util.Scanner;
class SaddlePoint {
public static void main(String[] args) {
Scanner ob = new Scanner(System.in);
System.out.println("Enter order of square matrix");
int n = ob.nextInt();
int A[][] = new int[n][n];
System.out.println("Enter a square matrix of order:" + n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
A[i][j] = ob.nextInt();
}
}
System.out.println("ORIGINAL MATRIX");
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print(A[i][j] + " ");
}
System.out.println("");
}
int min = 0, max = 0, c = 0;
for (int i = 0; i < n; i++) //Loop to find Saddle Point
{
min = 9999;
max = -9999;
for (int j = 0; j < n; j++) {
if (A[i][j] < min) {
min = A[i][j];
c = j;
}
}
for (int k = 0; k < n; k++) {
if (A[k][c] > max) {
max = A[k][c];
}
}
if (min == max) {
break;
}
}
if (min == max) {
System.out.println("Saddle Point:" + min);
} else {
System.out.println("No saddle point is present");
}
}
}