Kaynağa Gözat

getmiddlelast

Seth 5 yıl önce
ebeveyn
işleme
176a6bb096

+ 11
- 3
src/main/java/rocks/zipcode/quiz5/arrays/ArrayUtils.java Dosyayı Görüntüle

@@ -5,15 +5,23 @@ package rocks.zipcode.quiz5.arrays;
5 5
  */
6 6
 public class ArrayUtils {
7 7
     public static String getMiddleElement(String[] values) {
8
-        return null;
8
+
9
+        return values[values.length/2];
9 10
     }
10 11
 
11 12
     public static String[] removeMiddleElement(String[] values) {
12
-        return null;
13
+        String[] newArray = new String[values.length - 1];
14
+        for (int i = 0; i < values.length - 1; i++) {
15
+           if(!values[i].equals(getMiddleElement(values))){
16
+               newArray[i] = values[i];
17
+           }
18
+        }
19
+        return newArray;
13 20
     }
14 21
 
15 22
     public static String getLastElement(String[] values) {
16
-        return null;
23
+
24
+        return values[values.length -1];
17 25
     }
18 26
 
19 27
     public static String[] removeLastElement(String[] values) {