-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindMaxElement.java
More file actions
58 lines (45 loc) · 1.02 KB
/
FindMaxElement.java
File metadata and controls
58 lines (45 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package matrices;
import java.util.Scanner;
public class FindMaxElement {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int m,n;
System.out.println("Enter the row and column Size : ");
m = sc.nextInt();
n = sc.nextInt();
int[][] a = new int[m][n];
//initializing MAX element as INT_MIN
int maxElem = Integer.MIN_VALUE;
//read the matrix elements
System.out.println("Enter the Matrix Elements : ");
for(int i = 0;i<m;i++)
{
for(int j = 0;j<n;j++)
{
a[i][j] = sc.nextInt();
}
}
//these are to find the maximum element in an matrix
for(int i = 0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(a[i][j] > maxElem) {
maxElem = a[i][j];
}
}
}
System.out.println("Maximum Element in an Matrix is : "+maxElem);
}
}
/*
Output :
Enter the row and column Size :
3 4
Enter the Matrix Elements :
1 2 3 4
25 10 7 12
12 54 13 5
Maximum Element in an Matrix is : 54
*/