Java Program to Find All Palindromic Sub-Strings of a String
Given a string, the task is to count all palindrome substring in a given string.
Input : aba Output : 4 Explanation : All palindrome substring are : "aba" , "a" , "b", "a" Input : TENET Output : 7 Explanation : All palindrome sub-string are : "T" , "E" , "N", "E", "T" , "ENE" , "TENET"
- Take the substrings from the given string.
- Now check whether the substring is Palindrome or not.
- If the substring is Palindrome increment the count by 1 else if not count is not incremented.
- Return the count as it represents the number of substrings.
- Print and display on the console.
No.of palindromic substrings in the given string are 15
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.