Untitled

mail@pastecode.io avatar
unknown
java
a month ago
677 B
8
Indexable
Never
public class palindromeString {

    public static boolean checkExtremes(String str, int l, int r) {

        if (str.charAt(l) == str.charAt(r))
            return true;

        return false;

    }

    public static boolean checkPalindrome(String str, int l, int r) {

        if (l >= r)
            return true;

        if (checkExtremes(str, l, r)) {
            return checkPalindrome(str, l + 1, r - 1);
        }

        return false;
    }

    public static void main(String[] args) {

        String checkPalidrome = "RACECAR";

        System.out.println(checkPalindrome(checkPalidrome, 0, checkPalidrome.length() - 1));
    }

}
Leave a Comment