|
@@ -1,22 +1,39 @@
|
1
|
1
|
package rocks.zipcode.quiz5.arrays;
|
2
|
2
|
|
|
3
|
+import java.util.Arrays;
|
|
4
|
+
|
3
|
5
|
/**
|
4
|
6
|
* @author leon on 01/01/2019.
|
5
|
7
|
*/
|
6
|
8
|
public class ArrayUtils {
|
7
|
9
|
public static String getMiddleElement(String[] values) {
|
8
|
|
- return null;
|
|
10
|
+
|
|
11
|
+ return values[(values.length-1)/2];
|
9
|
12
|
}
|
10
|
13
|
|
11
|
14
|
public static String[] removeMiddleElement(String[] values) {
|
12
|
|
- return null;
|
|
15
|
+ String[] value = new String[values.length-1];
|
|
16
|
+ String check = getMiddleElement(values);
|
|
17
|
+ int count = 0;
|
|
18
|
+ for (int i = 0; i < values.length; i++) {
|
|
19
|
+ if (values[i] != check){
|
|
20
|
+ value[count] = values[i];
|
|
21
|
+ count++;
|
|
22
|
+ }
|
|
23
|
+
|
|
24
|
+ }
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+ return value;
|
13
|
28
|
}
|
14
|
29
|
|
15
|
30
|
public static String getLastElement(String[] values) {
|
16
|
|
- return null;
|
|
31
|
+
|
|
32
|
+ return values[values.length-1];
|
17
|
33
|
}
|
18
|
34
|
|
19
|
35
|
public static String[] removeLastElement(String[] values) {
|
20
|
|
- return null;
|
|
36
|
+
|
|
37
|
+ return Arrays.copyOf(values, values.length-1);
|
21
|
38
|
}
|
22
|
39
|
}
|