-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrintLargest_Smallest.java
53 lines (52 loc) · 1.61 KB
/
PrintLargest_Smallest.java
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
import java.util.*;
public class PrintLargest_Smallest{
public static int Largest(int arr[][]) {
int maxi=Integer.MIN_VALUE;
for(int i=0;i<arr.length;i++){
for(int j=0;j<arr[0].length;j++){
if (maxi<arr[i][j]){
maxi=arr[i][j];
}
}
}
return maxi;
}
public static int Smallest(int arr[][]) {
int mini=Integer.MAX_VALUE;
for(int i=0;i<arr.length;i++){
for(int j=0;j<arr[0].length;j++){
if (mini>arr[i][j]){
mini=arr[i][j];
}
}
}
return mini;
}
public static void PrintArray(int arr[][]) {
for(int i=0;i<arr.length;i++){
for(int j=0;j<arr[0].length;j++){
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter Row Number: ");
int row=sc.nextInt();
System.out.println("Enter Column Number: ");
int col=sc.nextInt();
int arr[][]=new int[row][col];
//Tahking Input
System.out.println("Enter Elements: ");
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
arr[i][j]=sc.nextInt();
}
}
PrintArray(arr);
System.out.println("Largest Element: "+Largest(arr));
System.out.println("Smallest Element: "+Smallest(arr));
sc.close();
}
}