diff --git a/homeworks/HW1/src/main/java/ru.atom/Util.java b/homeworks/HW1/src/main/java/ru.atom/Util.java index 383551b020..0dbaad4a80 100644 --- a/homeworks/HW1/src/main/java/ru.atom/Util.java +++ b/homeworks/HW1/src/main/java/ru.atom/Util.java @@ -1,14 +1,16 @@ package ru.atom; +import java.util.Arrays; +import java.util.Collections; + /** * In this assignment you need to implement the following util methods. * Note: - * throw new UnsupportedOperationException(); - is just a stub + * throw new UnsupportedOperationException(); - is just a stub */ public class Util { - /** * Returns the greatest of {@code int} values. * @@ -16,6 +18,15 @@ public class Util { * @return the largest of values. */ public static int max(int[] values) { + if (values.length > 0) { + int max = values[0]; + for (int i = 0; i < values.length; ++i) { + if (max < values[i]) { + max = values[i]; + } + } + return max; + } throw new UnsupportedOperationException(); } @@ -26,6 +37,13 @@ public static int max(int[] values) { * @return the sum of all values. */ public static long sum(int[] values) { + if (values.length > 0) { + long sum = 0; + for (int a : values) { + sum += a; + } + return sum; + } throw new UnsupportedOperationException(); }