import java.util.Scanner; public class Palindrome2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a word: "); String x = input.next(); int i, last; // Index of the characters that we are comparing last = x.length() - 1; boolean isPalindrome = true; // Initial assumption for ( i = 0; i < x.length()/2; i++ ) { if ( x.charAt( i ) != x.charAt( last-i ) ) { isPalindrome = false; // x is not a palindrome } } System.out.println(isPalindrome); } }