From 1ef700e8505e90e1df468f9e8164ed7e35e40a39 Mon Sep 17 00:00:00 2001 From: Bama Charan Chhandogi Date: Sun, 13 Aug 2023 01:36:39 +0530 Subject: [PATCH] Add IsEven Algorithm (#4301) Co-authored-by: BamaCharanChhandogi --- .../com/thealgorithms/bitmanipulation/IsEven.java | 12 ++++++++++++ .../thealgorithms/bitmanipulation/IsEvenTest.java | 14 ++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/main/java/com/thealgorithms/bitmanipulation/IsEven.java create mode 100644 src/test/java/com/thealgorithms/bitmanipulation/IsEvenTest.java diff --git a/src/main/java/com/thealgorithms/bitmanipulation/IsEven.java b/src/main/java/com/thealgorithms/bitmanipulation/IsEven.java new file mode 100644 index 00000000..c9129e47 --- /dev/null +++ b/src/main/java/com/thealgorithms/bitmanipulation/IsEven.java @@ -0,0 +1,12 @@ +package com.thealgorithms.bitmanipulation; + +/** + * Converts any Octal Number to a Binary Number + * @author Bama Charan Chhandogi (https://github.com/BamaCharanChhandogi) + */ + +public class IsEven { + public static boolean isEven(int number) { + return (number & 1) == 0; + } +} \ No newline at end of file diff --git a/src/test/java/com/thealgorithms/bitmanipulation/IsEvenTest.java b/src/test/java/com/thealgorithms/bitmanipulation/IsEvenTest.java new file mode 100644 index 00000000..2e33539f --- /dev/null +++ b/src/test/java/com/thealgorithms/bitmanipulation/IsEvenTest.java @@ -0,0 +1,14 @@ +package com.thealgorithms.bitmanipulation; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class IsEvenTest { + @Test + void testIsEven() { + assertEquals(true, IsEven.isEven(2)); + assertEquals(true, IsEven.isEven(-12)); + assertEquals(false, IsEven.isEven(21)); + } +}