Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions homeworks/HW1/src/main/java/ru.atom/Util.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
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.
*
* @param values an argument. Assume values.length > 0.
* @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();
}

Expand All @@ -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();
}

Expand Down