0% found this document useful (0 votes)
0 views2 pages

Utf 8

The Java program defines a class 'SaddlePoint' that identifies saddle points in a square matrix input by the user. It prompts the user to enter the matrix size and its elements, then checks each row for its minimum value and the corresponding column for its maximum value. If a saddle point is found, it is printed; otherwise, a message indicating no saddle point is displayed.

Uploaded by

Harshini Bonula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views2 pages

Utf 8

The Java program defines a class 'SaddlePoint' that identifies saddle points in a square matrix input by the user. It prompts the user to enter the matrix size and its elements, then checks each row for its minimum value and the corresponding column for its maximum value. If a saddle point is found, it is printed; otherwise, a message indicating no saddle point is displayed.

Uploaded by

Harshini Bonula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

*;
class SaddlePoint
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the order of the matrix : ");
int n=sc.nextInt();
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]=sc.nextInt();
}
}

/* Printing 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 every row
x = 0;
for(int j=0;j<n;j++)
{
if(A[i][j]<min)
{
min = A[i][j];
x = j; // 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[0][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("********");
}
}
}

You might also like