-
Notifications
You must be signed in to change notification settings - Fork 0
/
MinMaxArr.java
37 lines (32 loc) · 1.05 KB
/
MinMaxArr.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
#finding minimum and maximum element in 2d array
import java.util.Scanner;
public class MinMaxArr {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("enter the rows");
int row = sc.nextInt();
System.out.println("enter the columns");
int coln = sc.nextInt();
int arr[][] = new int[row][coln];
System.out.println("enter the array");
for(int i=0;i<row;i++) {
for (int j = 0; j < coln; j++) {
arr[i][j] = sc.nextInt();
}
}
int max = arr[0][0];
int min = arr[0][0];
for(int i=0;i<row;i++) {
for (int j = 0; j < coln; j++) {
if(arr[i][j]>max){
max = arr[i][j];
}
if(arr[i][j]<min){
min = arr[i][j];
}
}
}
System.out.println("max elenent is: "+max);
System.out.println("min element is : "+min);
}
}