Sfoglia il codice sorgente

squarearrayanalyzer

Lauren Green 6 anni fa
parent
commit
4ee82d4c3e

+ 28
- 1
src/main/java/rocks/zipcode/io/quiz3/arrays/SquareArrayAnalyzer.java Vedi File

@@ -5,6 +5,33 @@ package rocks.zipcode.io.quiz3.arrays;
5 5
  */
6 6
 public class SquareArrayAnalyzer {
7 7
     public static Boolean compare(Integer[] input, Integer[] squaredValues) {
8
-        return null;
8
+
9
+        if(input.length == squaredValues.length) {
10
+            input = squareValues(input);
11
+            boolean contains = false;
12
+            for(Integer i: input) {
13
+                if(!containsValue(squaredValues, i))
14
+                    return false;
15
+            }
16
+            return true;
17
+        }
18
+
19
+        return false;
20
+    }
21
+
22
+    public static Integer[] squareValues(Integer[] input) {
23
+        for (int i = 0; i < input.length; i++) {
24
+            input[i] = input[i] * input[i];
25
+        }
26
+        return input;
27
+    }
28
+
29
+    public static boolean containsValue(Integer[] input, Integer numb) {
30
+
31
+        for(Integer i: input) {
32
+            if(i.equals(numb))
33
+                return true;
34
+        }
35
+        return false;
9 36
     }
10 37
 }