I need to make a code testing if an inputted name is a palindrome. I wrote a method that is supposed to return a String (ex. "[name] is a palindrome.") to the main method. However, the compiler "cannot find symbol" of my final return value ("return palindrome;"). Could anyone please help? Thanks!
This is only the method I'm having trouble with; I can paste the main method, too, if someone wants me too, but it's not much.
public static String palindrome (String name) { int length = name.length(); int i = 0; while (i < length) { char first = name.charAt(i); String firstStr = first + ""; char last = name.charAt(length-1-i); String lastStr = last + ""; if (firstStr.equals (lastStr)) { i++; if (i == length - 1) { String palindrome = name + " is a palindrome."; } } else { String palindrome = name + " is not a palindrome."; } } return palindrome; }
Also- I'm new and don't know if this is the right forum. If it's not, please tell me which one is the correct forum to post this to. Thanks!


LinkBack URL
About LinkBacks
Reply With Quote