-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
39 lines (30 loc) · 1.1 KB
/
Solution.java
File metadata and controls
39 lines (30 loc) · 1.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
39
package com.javarush.task.task11.task1123;
//Jesus answered him, "You don't know what I am doing now, but you will understand later." (John 13:7)
public class Solution {
public static void main(String[] args) throws Exception {
int[] data = new int[]{1, 2, 3, 5, -2, -8, 0, 77, 5, 5};
Pair<Integer, Integer> result = getMinimumAndMaximum(data);
System.out.println("Minimum is " + result.x);
System.out.println("Maximum is " + result.y);
}
public static Pair<Integer, Integer> getMinimumAndMaximum(int[] array) {
if (array == null || array.length == 0) {
return new Pair<Integer, Integer>(null, null);
}
int min = array[0];
int max = array[0];
for (int i = 0; i < array.length - 1; i++) {
if (array[i]<min){min = array[i];}
if (array[i]>max){max = array[i];}
}
return new Pair<Integer, Integer>(min, max);
}
public static class Pair<X, Y> {
public X x;
public Y y;
public Pair(X x, Y y) {
this.x = x;
this.y = y;
}
}
}