From be9c15a64feacd20be842bdeaa582fa5b68ad1e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B0=D0=B9=D1=8B=D0=BC=D0=B1=D0=B5=D0=BA=20=D0=90?= =?UTF-8?q?=D0=B7=D0=B0=D1=82=D0=B1=D0=B5=D0=BA=D0=BE=D0=B2?= Date: Wed, 4 Dec 2019 15:30:06 +0600 Subject: [PATCH] home work1 --- homeworks/HW1/src/main/java/ru.atom/Util.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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(); }