Count palindrome substrings Given a string S, count and return the number of substrings of S that
  are palindromes. Single length substrings are also palindromes. We
  just have to count the substring that are palindrome. 
  
  INPUT: aba
   OUTPUT: 4
   EXPLANATION: String aba has a,b,a,aba as palindromic
  substrings.


My code is running correctly but I need more efficient code.

public class PalindromeSubstrings {

    public static int countPalindromeSubstrings(String s)
    {
        String a;
        int countSubs=s.length();
        for(int i=0;i&lt;s.length();i++)
        {
          for(int j=i+2;j&lt;=s.length();j++)
          {
            a=s.substring(i,j);
            countSubs+=count(a);
          }
        }
        return countSubs;
    }
    public static int count(String a)
    {
        for(int i=0;i&lt;a.length();i++)
        {
            if(a.charAt(i)!=a.charAt(a.length()-1-i))
                return 0;
        }
        return 1;
    }
}
Shouldn't the count method be called isPalindrome?
count/isPalindrome only needs to iterate over half the string: i&lt;a.length()/2. (Make sure to test it, it might be &lt;=)
You should use boolean instead of int for isPalindrome.
There's no need to create a temporary a variable in countPalindromeSubstrings.
count would probably make more sense than countSubs.
The whitespace seems off.
Keep your indentation consistent (I'm using 4 spaces since that's what I prefer and it's hard to tell what you prefer [I actually prefer tabs, but spaces are strongly recommended on this site]).
Stay consistent with your brace style. I personally prefer K&amp;R/Egyptian/whatever braces (the style you use around the class), but it seems you prefer ANSI/Allman/whatever braces (the style you use everywhere else in this code), so I'll use that.


Point 2 should provide about double the speed; the others probably won't change the speed much, put should still probably be made.

Result:

public class PalindromeSubstrings
{

    public static int countPalindromeSubstrings(String s)
    {
        int count = s.length();
        for(int i = 0; i &lt; s.length(); i++)
        {
            for(int j = i+2; j &lt;= s.length(); j++)
            {
                countSubs += isPalindrome(s.substring(i, j));
            }
        }
        return countSubs;
    }
    public static int isPalindrome(String a)
    {
        for(int i = 0; i &lt; a.length() / 2; i++)
        {
            if(a.charAt(i) != a.charAt(a.length() - 1 - i))
                return 0;
        }
        return 1;
    }
}