Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fix for problem 2413 #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
18 changes: 18 additions & 0 deletions src/main/java/com/fishercoder/solutions/_2413.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.fishercoder.solutions;

public class _2413 {

public static class Solution1 {
public int smallestEvenMultiple(int n) {
int maxNo = 2 * n;
int smallestMultiple = -1;
for(int i = 2; i <= maxNo; i += 2) {
if (i % n == 0 && i % 2 == 0) {
smallestMultiple = i;
break;
}
}
return smallestMultiple;
}
}
}
25 changes: 25 additions & 0 deletions src/test/java/com/fishercoder/_2413Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.fishercoder;

import com.fishercoder.solutions._2413;
import org.junit.BeforeClass;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class _2413Test {
private static _2413.Solution1 solution1;
private static int n;

@BeforeClass
public static void setup() {
solution1 = new _2413.Solution1();
}

@Test
public void test1() {
n = 99;
int actual = solution1.smallestEvenMultiple(n);
int expected = 198;
assertEquals(actual, expected);
}
}