-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlargesttwo.java
More file actions
37 lines (35 loc) · 1.17 KB
/
Copy pathlargesttwo.java
File metadata and controls
37 lines (35 loc) · 1.17 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
public class largesttwo {
public static void Largest(int arr[][]){
int largest = Integer.MIN_VALUE;
for(int i=0; i<arr.length;i++){
for(int j=0; j<arr[0].length; j++){
if(largest < arr[i][j]){
largest = arr[i][j];
}
}
}
System.out.println("Largest element is: "+ largest);
}
public static void Smallest(int arr[][]){
int smallest = Integer.MAX_VALUE;
for(int i=0; i<arr.length; i++){
for(int j=0; j<arr[0].length; j++){
if(smallest > arr[i][j]){
smallest = arr[i][j];
}
}
}
System.out.println("smallest element is:" + smallest);
}
public static void main(String args[]){
int matrix[][] = {{1,2,3,11},{4,5,6,12},{7,8,9,14}}; // 4*3 matrix row -major
for(int i=0; i<matrix.length; i++){
for(int j=0; j<matrix[0].length; j++){
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
Largest(matrix);
Smallest(matrix);
}
}