1 import java.util.Scanner;
2
3 publicclass Palindrome {
4 /** Main method */
5 publicstaticvoid main(String[] args) {
6 // Create a Scanner
7 Scanner input = new Scanner(System.in);
8
9 // Prompt the user to enter a string
10 System.out.print("Enter a string: ");
11 String s = input.nextLine();
12
13 // The index of the first character in the string
14 intlow = 0;
15
16 // The index of the last character in the string
17 inthigh = s.length() - 1;
18
19 booleanisPalindrome = true;
20 while (low < high) {
21 if (s.charAt(low) != s.charAt(high)) {
22 isPalindrome = false;
23 break;
24 }
25
26 low++;
27 high--;
28 }
29
30 if (isPalindrome)
31 System.out.println(s + " is a palindrome");
32 else
33 System.out.println(s + " is not a palindrome");
34 }
35 }