-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaddlePoint.java
More file actions
47 lines (46 loc) · 1.22 KB
/
Copy pathSaddlePoint.java
File metadata and controls
47 lines (46 loc) · 1.22 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
import java.util.*;
class SaddlePoint
{
static boolean findSaddlePoint(int mat[][], int n)
{
for(int i = 0; i < n; i++)
{
int min_row = mat[i][0], col_ind = 0;
for(int j = 1; j < n; j++)
{
if(min_row > mat[i][j])
{
min_row = mat[i][j];
col_ind = j;
}
}
int k;
for (k = 0; k < n; k++)
{
if (min_row < mat[k][col_ind])
break;
}
if (k == n)
{
System.out.println("Value of Saddle Point : " + min_row);
return true;
}
}
return false;
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter size of array :");
int n=sc.nextInt();
int mat[][]=new int[n][n];
System.out.println("Enter the elements of array :");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
mat[i][j]=sc.nextInt();
}
if (findSaddlePoint(mat, n) == false)
System.out.println("No Saddle Point ");
}
}