Palindrome

The word palindrome is a combination of 2 Greek words Palin, which means back or again and dromos, which means direction.

Aibohphobia is the fear of palindromes which itself is a palindrome.

Ailihphilia love of palindromes which again is a palindrome.

The longest single-word palindrome is tattarrattat, which means knocking on the door.

package org.wesome.dsalgo;

public class Palindrome {
    static boolean isPalindrome(String string) {
        for (int i = 0; i < string.length() / 2; i++) {
            if (string.charAt(i) != string.charAt(string.length() - 1 - i)) {
                return false;
            }
        }
        return true;
    }

}
package org.wesome.dsalgo;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class PalindromeTest {
    @Test
    void palindromeTest1() {
        Assertions.assertTrue(Palindrome.isPalindrome("aibohphobia"));
    }

    @Test
    void palindromeTest2() {
        Assertions.assertTrue(Palindrome.isPalindrome("ailihphilia"));
    }

    @Test
    void palindromeTest3() {
        Assertions.assertFalse(Palindrome.isPalindrome("Step on no pets"));
    }

    @Test
    void palindromeTest4() {
        Assertions.assertTrue(Palindrome.isPalindrome("madam"));
    }
}
plugins {
    id 'java'
}

group = 'org.wesome'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_1_8

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
}

test {
    useJUnitPlatform()
}

 

follow us on