From: Developing Algorithms Using Strings Quiz
import java.util.Scanner;
public class Main
{
public static void palindromeChecker(String str)
{
String noSpace = removeSpaces(str);
String flipped = reverseString(noSpace);
if (noSpace.equals(flipped))
{
System.out.print(str + " is a palindrome");
}
else
{
System.out.print(str + " is not a palindrome");
}
}
public static String removeSpaces(String st)
{
String saved = "";
for(int i=0; i<st.length();i++)
{
if(!(st.substring(i, i+1).equals(" ")))
{
saved += st.substring(i, i+1);
}
}
return saved;
}
public static String reverseString(String strr)
{
String result = "";
for (int i = 0; i < strr.length(); i++)
{
String a = strr.substring(i, i + 1);
result = a + result;
}
return result;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String in = input.nextLine();
palindromeChecker(in);
}
}