Here
is the Program of Find Smallest and Largest Element from Square Matrix with Position
Checkout:- Program To Check Whether a Matrix is Sparse Matrix
Checkout:- Java Program to Multiply Two Matrices
We are uploading these types of program. However, if you need fully compiled solution of any type of Java program then simply leave a comment below, we will help you at the earliest. 😊😊
import java.util.*;
class Largest_Smallest_Number_Matrix
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int small=0,large=0;
int smallRowindex=0,smallColindex=0;
int largeRowindex=0,largeColindex=0;
System.out.println("Enter the Number of Rows");
int r=sc.nextInt();
System.out.println("Enter the Number of Columns");
int c=sc.nextInt();
int arr[][]=new int[r][c];
System.out.println("Enter the Elements of Matrix");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
arr[i][j]=sc.nextInt();
}
}
System.out.println("Input Matrix:");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println(" ");
}
large=arr[0][0];
small=arr[0][0];
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
if(arr[i][j]>large)
{
large=arr[i][j];
largeRowindex=i;
largeColindex=j;
}
else if(arr[i][j]<small)
{
small=arr[i][j];
smallRowindex=i;
smallColindex=j;
}
}
}
System.out.println("LARGEST NUMBER="+large);
System.out.println("ROW="+largeRowindex);
System.out.println("COLUMN="+largeColindex);
System.out.println(" ");
System.out.println("SMALLEST NUMBER="+small);
System.out.println("ROW="+smallRowindex);
System.out.println("COLUMMN="+smallColindex);
}
}
-------------
OUTPUT:-
-------------
Enter the Number of Rows
4
Enter the Number of Columns
4
Enter the Elements of Matrix
1
4
5
2
3
6
7
8
9
6
5
4
1
2
3
5
Input Matrix:
1 4 5 2
3 6 7 8
9 6 5 4
1 2 3 5
LARGEST NUMBER=9
ROW=2
COLUMN=0
----------------------------
SMALLEST NUMBER=1
ROW=0
COLUMMN=0
-----------------------------
Checkout:- Java Program To Check Two Matrices Are Equal
0 Comments
Just write down your question to get the answer...