diff --git a/src/main/java/com/fishercoder/solutions/_2413.java b/src/main/java/com/fishercoder/solutions/_2413.java new file mode 100644 index 0000000000..5eecf046b9 --- /dev/null +++ b/src/main/java/com/fishercoder/solutions/_2413.java @@ -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; + } + } +} diff --git a/src/test/java/com/fishercoder/_2413Test.java b/src/test/java/com/fishercoder/_2413Test.java new file mode 100644 index 0000000000..01dffef444 --- /dev/null +++ b/src/test/java/com/fishercoder/_2413Test.java @@ -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); + } +}
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: