-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxMinArray.java
More file actions
38 lines (35 loc) · 1 KB
/
MaxMinArray.java
File metadata and controls
38 lines (35 loc) · 1 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
public class MaxMinArray {
public static void main(String[] args) {
System.out.println("Welcome to Max and Min\n");
int[] numArr = ArrayUtility.inputArray();
int max = max(numArr);
int min = min(numArr);
System.out.println("Max of the Array is: " + max);
System.out.println("Min of the Array is: " + min);
}
public static int min(int[] numArr) {
int min = Integer.MAX_VALUE;
int i = 0;
while (i < numArr.length) {
if (min > numArr[i]) {
min = numArr[i];
}
i++;
}
return min;
}
public static int max(int[] numArr) {
if (numArr.length == 0) {
return Integer.MIN_VALUE;
}
int max = numArr[0];
int i = 1;
while (i < numArr.length) {
if (max < numArr[i]) {
max = numArr[i];
}
i++;
}
return max;
}
}