File tree 4 files changed +43
-0
lines changed
4 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 196
196
- [ Sum of differences in array] ( sum-of-differences-in-array " 5b73fe9fb3d9776fbf00009e ")
197
197
- [ Sum of Multiples] ( sum-of-multiples " 57241e0f440cd279b5000829 ")
198
198
- [ Sum of positive] ( sum-of-positive " 5715eaedb436cf5606000381 ")
199
+ - [ Sum The Strings] ( sum-the-strings " 5966e33c4e686b508700002d ")
199
200
- [ Sum without highest and lowest number] ( sum-without-highest-and-lowest-number " 576b93db1129fcf2200001e6 ")
200
201
- [ Surface Area and Volume of a Box] ( surface-area-and-volume-of-a-box " 565f5825379664a26b00007c ")
201
202
- [ Swap Values] ( swap-values " 5388f0e00b24c5635e000fc6 ")
Original file line number Diff line number Diff line change
1
+ # [ Sum The Strings] ( https://www.codewars.com/kata/sum-the-strings " https://www.codewars.com/kata/5966e33c4e686b508700002d ")
2
+
3
+ Create a function that takes 2 integers in form of a string as an input, and outputs the sum (also as a string):
4
+
5
+ Example: (** Input1, Input2 -->Output** )
6
+
7
+ ```
8
+ "4", "5" --> "9"
9
+ "34", "5" --> "39"
10
+ "", "" --> "0"
11
+ "2", "" --> "2"
12
+ "-5", "3" --> "-2"
13
+ ```
14
+
15
+ Notes:
16
+
17
+ - If either input is an empty string, consider it as zero.
18
+
19
+ - Inputs and the expected output will never exceed the signed 32-bit integer limit (` 2^31 - 1 ` )
Original file line number Diff line number Diff line change
1
+ interface Kata {
2
+ static String sumStr (String a , String b ) {
3
+ return (a .isEmpty () ? 0 : Integer .parseInt (a )) + (b .isEmpty () ? 0 : Integer .parseInt (b )) + "" ;
4
+ }
5
+ }
Original file line number Diff line number Diff line change
1
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
2
+
3
+ import org .junit .jupiter .params .ParameterizedTest ;
4
+ import org .junit .jupiter .params .provider .CsvSource ;
5
+
6
+ class SolutionTest {
7
+ @ ParameterizedTest
8
+ @ CsvSource (textBlock = """
9
+ 4, 5, 9
10
+ 34, 5, 39
11
+ '', 8, 8
12
+ 9, '', 9
13
+ '', '', 0
14
+ """ )
15
+ void sample (String a , String b , String expected ) {
16
+ assertEquals (expected , Kata .sumStr (a , b ));
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments