I need to find out if a phone number is a palindrome. I have this code:
public static boolean isPalindrome(String j)
{
boolean pali;
String rev = "";
String reverse = new StringBuffer(j).reverse().toString();
j.toString();
if (j.equals(reverse))
pali = false;
else if (!j.equals(reverse))
pali = true;
return pali;
}
This code is giving me this error: The local variable may not have been initialized. How can I fix this?
By initializing the local variable:
boolean pali = false; // Default value before you know it is a palindrome