From 622858b055493949311da425992176e3713292f3 Mon Sep 17 00:00:00 2001 From: Naveenkumarsuk Date: Sat, 12 Jul 2025 18:32:15 +0100 Subject: [PATCH 1/2] Add EvenOddChecker to check if number is even or odd --- .../com/thealgorithms/others/EvenOddChecker.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/com/thealgorithms/others/EvenOddChecker.java diff --git a/src/main/java/com/thealgorithms/others/EvenOddChecker.java b/src/main/java/com/thealgorithms/others/EvenOddChecker.java new file mode 100644 index 000000000000..8c32d41b7c90 --- /dev/null +++ b/src/main/java/com/thealgorithms/others/EvenOddChecker.java @@ -0,0 +1,12 @@ +package com.thealgorithms.others; + +public class EvenOddChecker { + public static String checkEvenOdd(int number) { + return number % 2 == 0 ? "Even" : "Odd"; + } + + public static void main(String[] args) { + int test = 7; + System.out.println(test + " is " + checkEvenOdd(test)); + } +} From fd0691063799fa05e2cf3de478c24810f299b6c7 Mon Sep 17 00:00:00 2001 From: Naveenkumarsuk Date: Sat, 12 Jul 2025 18:46:26 +0100 Subject: [PATCH 2/2] Add PalindromeChecker to check if a string is a palindrome --- .../strings/PalindromeChecker.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/main/java/com/thealgorithms/strings/PalindromeChecker.java diff --git a/src/main/java/com/thealgorithms/strings/PalindromeChecker.java b/src/main/java/com/thealgorithms/strings/PalindromeChecker.java new file mode 100644 index 000000000000..39715c15c83e --- /dev/null +++ b/src/main/java/com/thealgorithms/strings/PalindromeChecker.java @@ -0,0 +1,41 @@ +package com.thealgorithms.strings; + +/** + * Utility class to check if a string is a palindrome. + */ +public class PalindromeChecker { + + /** + * Checks if the given input is a palindrome. + * Ignores spaces, punctuation, and case. + * + * @param input the string to check + * @return true if it's a palindrome, false otherwise + */ + public static boolean isPalindrome(String input) { + if (input == null) { + return false; + } + // Remove non-letter characters and convert to lowercase + String cleaned = input.replaceAll("[^a-zA-Z]", "").toLowerCase(); + int left = 0; + int right = cleaned.length() - 1; + + while (left < right) { + if (cleaned.charAt(left) != cleaned.charAt(right)) { + return false; + } + left++; + right--; + } + + return true; + } + + public static void main(String[] args) { + String test1 = "A man a plan a canal Panama"; + String test2 = "OpenAI"; + System.out.println("\"" + test1 + "\" is palindrome? " + isPalindrome(test1)); + System.out.println("\"" + test2 + "\" is palindrome? " + isPalindrome(test2)); + } +}