I am building a class that checks if the input contains palindromes and returns only the palindrome terms if they exist. I have been able to develop the following, and it compiles and runs without errors, but I am not getting any return from it.
Can anyone spot where my error lies?
public class Palindrome {
public static boolean isPalindrome(String word) {
String back = word.charAt(word.length() - 1) + "";
for (int i = word.length() - 2; i >= 0; i--) {
back = back + word.charAt(i);
}
if (word == back) {
return true;
}
return false;
}
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
if (isPalindrome(args[i]) == true) {
System.out.println(args[i]);
}
}
}
}
I believe the issue lies in the main method, specifically within the if statement, but I'm not exactly sure why it's not working.
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
if (isPalindrome(args[i]) == true) {
System.out.println(args[i]);
}
}
}
Thank you in advance for any help offered. I appreciate your time!