|
@@ -5,6 +5,34 @@ 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
|
+ Boolean[] allFlags = new Boolean[input.length];
|
|
9
|
+
|
|
10
|
+ Integer[] inputSquared = squareEachValue(input);
|
|
11
|
+
|
|
12
|
+ for (Integer aInteger : inputSquared) {
|
|
13
|
+ for (int i = 0; i < squaredValues.length; i++) {
|
|
14
|
+ if (aInteger.equals(squaredValues[i])) {
|
|
15
|
+ allFlags[i] = true;
|
|
16
|
+ }
|
|
17
|
+ }
|
|
18
|
+ }
|
|
19
|
+
|
|
20
|
+ for (Boolean flag : allFlags) {
|
|
21
|
+ if (!flag) {
|
|
22
|
+ return false;
|
|
23
|
+ }
|
|
24
|
+ }
|
|
25
|
+
|
|
26
|
+ return true;
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ public static Integer[] squareEachValue(Integer[] input) {
|
|
30
|
+ Integer[] squared = new Integer[input.length];
|
|
31
|
+
|
|
32
|
+ for (int i = 0; i < input.length; i++) {
|
|
33
|
+ squared[i] = input[i] * input[i];
|
|
34
|
+ }
|
|
35
|
+
|
|
36
|
+ return squared;
|
9
|
37
|
}
|
10
|
38
|
}
|