Saddle point program
Write a program in Java to input the size of a square matrix from the user. Then allow the user to fill the matrix with integers. Now do the following:
Saddle point program
Write a program in Java to input the size of a square matrix from the user. Then allow the user to fill the matrix with integers. Now do the following:
- Display the original matrix.
- Display the saddle point of the matrix if one exists, otherwise display “No saddle point”.
A saddle point of a matrix is the element in the matrix which is the smallest in its row, and the largest in its column.
Example:
INPUT:
N = 3
1 2 3
4 5 6
7 8 9
OUTPUT:
Original Matrix:
1 2 3
4 5 6
7 8 9
Saddle point = 7.
//This program finds the lowest element in the row and checks whether it value is the highest in that particular column
import java.io.*;
class SaddlePoint
{
public static void main() throws IOException
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.print("Enter the order of the matrix : ");
int n=Integer.parseInt(br.readLine());
int A[[]=new int[n][n];
System.out.println("Inputting the elements in the
matrix");
System.out.println("******");
for(int i=0;i<n;i++)
{
for(int j=0; j<n; j++)
{
System.out.print("Enter Element at ("+i+"]["+j+"]
A[i][j]=Integer.parseInt(br.readLine());
/* Print the Original Matrix */
**
");
System.out.println("**
System.out.println("The Original Matrix is");
for(int i=0;i<n;i++)
{
for(int j=0; j<n; j++)
{
System.out.print(A[i][j]+"\t");
}
System.out.println();
}
int max. min, X, F=0;
for(int i=0;i<n;i++)
/* Finding the minimum element of a row */
min = A[i][0]; // Initializing min with first element of each row
x = 0;
for(int j =0; j<n; j++)
{
if(A[i][j]<min)
min = A[i][j]:
X = ji / Saving the column position of the
minimum element of the row
}
}
/* Finding the maximum element in the column
* corresponding to the minimum element of row */
max = A[O][x]; // Initializing max with first element of that column
for(int k=0; k<n;k++)
{
if(A[k][x]>max)
{
max = A[k][x];
}
/* If the minimum of a row is same as maximum of the corresponding column. then, we have that element as the Saddle point */
if(max==min)
{
System.out.println("**
System.out.println("Saddle point = "+max);
**");
System.out.println("* f=1;***"):
}
if(f==0)
{
System.out.println("**
**");
System.out.println("No saddle point");
***");
System.out.println("
}Related Posts
Continue learning with these related articles

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.

ISC Practical 2027: Digital Lock Security Code Analyzer – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 number-logic question: for a 5 to 10 digit security code, find the first and last digits, odd and even position sums, product of non-zero digits, digit frequency and classify the code as STRONG, MODERATE or WEAK.

Boolean Algebra for ISC Class 12: Laws, Canonical SOP and POS, and Simplification
ISC Class 12 Computer Science notes on Boolean algebra: all the laws and theorems, duality, De Morgan's laws, minterms and maxterms, converting to canonical SOP and POS, and step-by-step algebraic simplification with solved examples.