8000 Kyu 8 | Array Plus array · danielex1999/CodeWars-Java@4b584e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4b584e5

Browse files
committed
Kyu 8 | Array Plus array
1 parent 77b45ae commit 4b584e5

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

src/main/java/kyu8/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Kata Found realized
3030

3131
- [Area or Perimeter](areaOrPerimeter)
3232

33+
- [Array plus array](arrayPlusArray)
34+
3335
- [Find Nearest square number](findNearestSquareNumber)
3436

3537

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Array plus array
2+
3+
I'm new to coding and now I want to get the sum of two arrays...actually the sum of all their elements. I'll appreciate
4+
for your help.
5+
6+
P.S. Each array includes only integer numbers. Output is a number too.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package kyu8.arrayPlusArray;
2+
3+
public class Sum {
4+
public static int arrayPlusArray(int[] arr1, int[] arr2) {
5+
int sum1 = 0;
6+
int sum2 = 0;
7+
int result = 0;
8+
for (int num : arr1) {
9+
sum1 = sum1 + num;
10+
}
11+
for (int num : arr2) {
12+
sum2 = sum2 + num;
13+
}
14+
result = sum1 + sum2;
15+
return result;
16+
}
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package kyu8.arrayPlusArray;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
public class testSum {
8+
@Test
9+
public void sampleTests() {
10+
assertEquals(21, Sum.arrayPlusArray(new int[]{1,2,3}, new int[]{4,5,6}));
11+
assertEquals(-21, Sum.arrayPlusArray(new int[]{-1,-2,-3}, new int[]{-4,-5,-6}));
12+
assertEquals(15, Sum.arrayPlusArray(new int[]{0,0,0}, new int[]{4,5,6}));
13+
assertEquals(2100, Sum.arrayPlusArray(new int[]{100,200,300}, new int[]{400,500,600}));
14+
}
15+
}

0 commit comments

Comments
 (0)
0