-
Notifications
You must be signed in to change notification settings - Fork 0
/
MinimumElement050.java
39 lines (29 loc) · 1.01 KB
/
MinimumElement050.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
import java.util.*;
public class MinimumElement050 {
public static int[] readIntegers() {
Scanner scan = new Scanner(System.in);
System.out.print("Enter the integers delimited with a ', ': ");
String listOfIntegers = scan.nextLine();
String[] integerList = listOfIntegers.split(", ");
int[] intArray = new int[integerList.length];
for (int index = 0; index < integerList.length; index++) {
intArray[index] = Integer.parseInt(integerList[index]);
}
scan.close();
return intArray;
}
public static int findMin(int[] intArray) {
Arrays.sort(intArray);
return intArray[0];
}
public static int findMax(int[] intArray) {
Arrays.sort(intArray);
return intArray[intArray.length - 1];
}
public static void main(String... args) {
int[] intArray = readIntegers();
System.out.println("Array: " + Arrays.toString(intArray));
System.out.println("Minimum Value: " + findMin(intArray));
System.out.println("Maximum Value: " + findMax(intArray));
}
}