{"id":1400,"date":"2022-03-03T19:24:14","date_gmt":"2022-03-03T19:24:14","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1400"},"modified":"2022-03-03T19:24:14","modified_gmt":"2022-03-03T19:24:14","slug":"program-to-check-palindrome-string-using-recursion","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/03\/03\/program-to-check-palindrome-string-using-recursion\/","title":{"rendered":"Program to check palindrome string using recursion"},"content":{"rendered":"\n<p><strong>Program: Check whether String is palindrome using recursion<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package beginnersbook.com;\nimport java.util.Scanner;\nclass PalindromeCheck\n{\n    \/\/My Method to check\n    public static boolean isPal(String s)\n    {   \/\/ if length is 0 or 1 then String is palindrome\n        if(s.length() == 0 || s.length() == 1)\n            return true; \n        if(s.charAt(0) == s.charAt(s.length()-1))\n        \/* check for first and last char of String:\n         * if they are same then do the same thing for a substring\n         * with first and last char removed. and carry on this\n         * until you string completes or condition fails\n         * Function calling itself: Recursion\n         *\/\n        return isPal(s.substring(1, s.length()-1));\n\n        \/* If program control reaches to this statement it means\n         * the String is not palindrome hence return false.\n         *\/\n        return false;\n    }\n\n    public static void main(String&#91;]args)\n    {\n    \t\/\/For capturing user input\n        Scanner scanner = new Scanner(System.in);\n        System.out.println(\"Enter the String for check:\");\n        String string = scanner.nextLine();\n        \/* If function returns true then the string is\n         * palindrome else not\n         *\/\n        if(isPal(string))\n            System.out.println(string + \" is a palindrome\");\n        else\n            System.out.println(string + \" is not a palindrome\");\n    }\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter the String for check:\nqqaabb\nqqaabb is not a palindrome<\/code><\/pre>\n\n\n\n<p>Output 2:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter the String for check:\ncocoococ\ncocoococ is a palindrome<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Program: Check whether String is palindrome using recursion Output: Output 2:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[496],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1400"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=1400"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1400\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}