Khalil Malik Saboor 6 yıl önce
ebeveyn
işleme
5ccf4c57e7

+ 14
- 12
src/main/java/io/zipcoder/ArrayDrills.java Dosyayı Görüntüle

@@ -73,12 +73,12 @@ public class ArrayDrills {
73 73
      *           middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
74 74
      */
75 75
     public Integer[] middleWay(Integer[] input1, Integer[] input2){
76
+        Integer [] myArray = new Integer[2];
76 77
 
77
-        Integer newArr [] = {};
78
+        if (input1.length % 2 != 0 && input2.length % 2 != 0){
78 79
 
79
-        if(newArr.length % 2 == 0){
80 80
 
81
-        } else{
81
+        } else if(input1.length % 2 == 0 && input2.length % 2 == 0){
82 82
 
83 83
         }
84 84
         return null;
@@ -91,13 +91,10 @@ public class ArrayDrills {
91 91
      * Return the array which has the largest sum. In event of a tie, return a.
92 92
      */
93 93
     public Integer[] biggerTwo(Integer[] a, Integer[] b){
94
-
95
-        int Sum = a[0] + a[1] -b[0]-b[1];
96
-        if (Sum >= 0){
97
-            return a;
98
-
94
+        if (a[0] + a[1] < b[0] + b[1]){
95
+            return b;
99 96
         }
100
-        return b;
97
+        return a;
101 98
     }
102 99
 
103 100
     /**
@@ -108,10 +105,15 @@ public class ArrayDrills {
108 105
      */
109 106
     public Integer[] midThree(Integer[] nums){
110 107
 
111
-        if(nums.length % 2 == 0){
108
+        Integer [] myArray = new Integer[3];
112 109
 
113
-        }
110
+        Integer middle = nums.length/2;
114 111
 
115
-        return null;
112
+        myArray[0] = nums[middle-1];
113
+        myArray[1] =  nums[middle];
114
+        myArray[2] = nums[middle+1];
115
+
116
+
117
+     return myArray;
116 118
     }
117 119
 }

+ 1
- 1
src/test/java/io/zipcoder/ArrayDrillsTest.java Dosyayı Görüntüle

@@ -179,7 +179,7 @@ public class ArrayDrillsTest {
179 179
     public void biggerTwo3(){
180 180
         Integer[] inputArray1 = {-1 ,20};
181 181
         Integer[] inputArray2 = {2, 15};
182
-        Integer[] expected = {1,20};
182
+        Integer[] expected = {-1,20};
183 183
         Integer[] actual = arrayDrills.biggerTwo(inputArray1, inputArray2);
184 184
         Assert.assertArrayEquals(expected, actual);
185 185
     }

BIN
target/classes/io/zipcoder/ArrayDrills.class Dosyayı Görüntüle


BIN
target/test-classes/io/zipcoder/ArrayDrillsTest.class Dosyayı Görüntüle