Skip to content
Open
Show file tree
Hide file tree
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
27 changes: 9 additions & 18 deletions app/src/main/java/control/Single.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ public class Single {
* @return The sum of the first n natural numbers.
*/
public static int sumRange(int n) {
int[] arr = new int[n];
int sum = 0;
for (int i = 0; i < n; i++) {
arr[i] = i;
}
for (int i : arr) {
sum += i;
}
return sum;
return n * (n + 1) / 2;
}

/**
Expand All @@ -29,10 +21,10 @@ public static int sumRange(int n) {
* @return The maximum value in the array.
*/
public static int maxArray(int[] arr) {
int max = 0;
for (int i : arr) {
if (i > max) {
max = i;
int max = arr[0];
for (int i = 1; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
Expand All @@ -45,13 +37,12 @@ public static int maxArray(int[] arr) {
* @param m The modulus.
*/
public static int sumModulus(int n, int m) {
Vector<Integer> multiples = new Vector<Integer>();
int sum = 0;
for (int i = 0; i < n; i++) {
if (i % m == 0) {
multiples.add(i);
sum += i;
}
}

return multiples.stream().mapToInt(Integer::valueOf).sum();
return sum;
}
}
}
Empty file modified gradlew
100755 → 100644
Empty file.