# Program to find the saddle point coordinates in a given matrix

Program to find the saddle point coordinates in a given matrix is discussed here.A saddle point is an element of the matrix, which is the minimum element in its row and the maximum in its column.

For example, consider the matrix given below

Mat =
1 2 3
4 5 6
7 8 9

Here, 7 is the saddle point because it is the minimum element in its row and maximum element in its column.

```import java.util.Scanner;

public class Main
{
public static void main(String[] args)
{
int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int m = 3,k;
int min = 0;
int max = 0;
int [][]pos = new int;
System.out.print(“nThe matrix is n”);
int i,j;
for (i = 0; i < m; i++)
{
for (j = 0; j < m; j++)
{
System.out.print(matrix[i][j] + ” ” );
}
System.out.println();
}
/* find the saddle points in the given matrix */
for (i = 0; i < m; i++)
{
min = matrix[i];
for (j = 0; j < m; j++)
{
if (min >= matrix[i][j])
{
min = matrix[i][j];
pos = i;
pos = j;
}
}
j = pos;
max = matrix[j];
for (k = 0; k < m; k++)
{
if (max <= matrix[k][j])
{
max = matrix[i][j];
pos = k;
pos = j;
}
}
/* saddle point is the minimum of a row and maximum of the column */
if (min == max)
{
if (pos == pos &&pos == pos)
{
System.out.print(“nSaddle point ( ” + pos + “,” + pos + ” ) : ” + max + “n”);
}
}
}
}

}```

Output

Enter the square matrix order : 3
Input the matrix : 1 2 3 4 5 6 7 8 9
The matrix is :
1 2 3
4 5 6
7 8 9