From 92d876711113ab0ce314e25b55bbe8a62bd3f19e Mon Sep 17 00:00:00 2001 From: ashmichheda Date: Sat, 29 Oct 2022 19:03:16 -0700 Subject: [PATCH] add fix for problem 2413 --- .../java/com/fishercoder/solutions/_2413.java | 18 +++++++++++++ src/test/java/com/fishercoder/_2413Test.java | 25 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/main/java/com/fishercoder/solutions/_2413.java create mode 100644 src/test/java/com/fishercoder/_2413Test.java 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); + } +}