Question
program to find largest element of matrix
Matrix:
[9, 8, 7]
[6, 5, 4]
[3, 2, 1]
LARGEST ELEMENTS OF MATRIX:9
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
import java.util.Scanner;
public class LargestElementsOfMatrix
{
public static void main(String[] args)
{
int row=0,col=0,i=0,j=0,max=0;
int a[][];
Scanner sc=new Scanner(System.in);
System.out.println("ENTER THE NUMBER OF ROW OF MATRIX");
row=sc.nextInt();
System.out.println("ENTER THE NUMBER OF COLUMN OF MATRIX");
col=sc.nextInt();
a=new int[row][col];
System.out.println("ENTER THE ELEMENTS IN MATRIX");
for(i=0;i< row;i++)
{
for(j=0;j< col;j++)
{
a[i][j]=sc.nextInt();
}
}
max=a[0][0];
for(i=0;i< row;i++)
{
for(j=0;j< col;j++)
{
if(a[i][j]>max)
{
max=a[i][j];
}
}
}
System.out.println("LARGEST ELEMENTS OF MATRIX:"+max);
}
}