-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxAndMinNumber.java
More file actions
44 lines (36 loc) · 1.05 KB
/
MaxAndMinNumber.java
File metadata and controls
44 lines (36 loc) · 1.05 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
39
40
41
42
43
44
public class MaxAndMinNumber {
public static void main(String[] args) {
System.out.println("Welcome to Max and Min Number Finder");
int[] InputArray = arrayInputUtility.inputArray();
if (InputArray.length == 0) {
System.out.println("Its Invailed Array");
}else{
int MaxNum = max(InputArray);
int MinNum = min(InputArray);
System.out.println("MaxNum = " + MaxNum);
System.out.println("MinNum = " + MinNum);
}
}
public static int min (int[] myArray){
int min = myArray[0] ;
int i = 1;
while (i < myArray.length) {
if (myArray[i] < min ) {
min = myArray[i];
}
i++;
}
return min;
}
public static int max (int[] myArray) {
int max = myArray[0];
int i = 1;
while (i < myArray.length) {
if (myArray[i] > max) {
max = myArray[i];
}
i++;
}
return max;
}
}