Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 92d8767

Browse files
committedOct 30, 2022
add fix for problem 2413
1 parent 555f2ec commit 92d8767

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
 
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _2413 {
4+
5+
public static class Solution1 {
6+
public int smallestEvenMultiple(int n) {
7+
int maxNo = 2 * n;
8+
int smallestMultiple = -1;
9+
for(int i = 2; i <= maxNo; i += 2) {
10+
if (i % n == 0 && i % 2 == 0) {
11+
smallestMultiple = i;
12+
break;
13+
}
14+
}
15+
return smallestMultiple;
16+
}
17+
}
18+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._2413;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _2413Test {
10+
private static _2413.Solution1 solution1;
11+
private static int n;
12+
13+
@BeforeClass
14+
public static void setup() {
15+
solution1 = new _2413.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
n = 99;
21+
int actual = solution1.smallestEvenMultiple(n);
22+
int expected = 198;
23+
assertEquals(actual, expected);
24+
}
25+
}

0 commit comments

Comments
 (0)
Please sign in to comment.