// PalTest.java // Written by THC for CS 5 Short Assignment 4. // Asks for a string, constructs the reversal of the string, // and says whether the string is a palindrome. import java.util.Scanner; public class PalTester { public static void main(String[] args) { // Get a string to reverse. Scanner input = new Scanner(System.in); System.out.print("Enter a string: "); String text = input.nextLine(); // Create the reversed version of text, one character at a time. String reversal = ""; for (int i = 0; i < text.length(); i++) reversal = text.charAt(i) + reversal; System.out.println("The reversed string is " + reversal); // A string is a palindrome if it's the same as its reversal. if (text.equals(reversal)) System.out.println(text + " is a palindrome"); else System.out.println(text + " is not a palindrome"); } }