forked from iRupam/NewtonSchoolInfinityJune21
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxAndMinInArray.java
More file actions
38 lines (31 loc) · 1.08 KB
/
MaxAndMinInArray.java
File metadata and controls
38 lines (31 loc) · 1.08 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
package InfinityJune21.DoubtSessionJul3;
import java.util.Scanner;
public class MaxAndMinInArray {
public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter number of testcases: ");
int T = scanner.nextInt();
for(int i = 0; i < T; i++) {
System.out.println("Enter size of the array: ");
int N = scanner.nextInt();
int arr[] = new int[N];
System.out.println("Enter " + N + " elements: ");
for(int j = 0; j < N; j++) {
arr[j] = scanner.nextInt();
}
int min = arr[0];
int max = arr[0];
for(int j = 1; j < N; j++) {
if(arr[j] < min) {
min = arr[j];
}
if(arr[j] > max) {
max = arr[j];
}
}
System.out.println("Min: " + min);
System.out.println("Max: " + max);
System.out.println();
}
}
}