1import java.util.*;
2class PalindromeExample2
3{
4 public static void main(String args[])
5 {
6 String original, reverse = ""; // Objects of String class
7 Scanner in = new Scanner(System.in);
8 System.out.println("Enter a string/number to check if it is a palindrome");
9 original = in.nextLine();
10 int length = original.length();
11 for ( int i = length - 1; i >= 0; i-- )
12 reverse = reverse + original.charAt(i);
13 if (original.equals(reverse))
14 System.out.println("Entered string/number is a palindrome.");
15 else
16 System.out.println("Entered string/number isn't a palindrome.");
17 }
18}
1public class Palindrome {
2
3 public static void main(String[] args) {
4
5 int num = 121, reversedInteger = 0, remainder, originalInteger;
6
7 originalInteger = num;
8
9 // reversed integer is stored in variable
10 while( num != 0 )
11 {
12 remainder = num % 10;
13 reversedInteger = reversedInteger * 10 + remainder;
14 num /= 10;
15 }
16
17 // palindrome if orignalInteger and reversedInteger are equal
18 if (originalInteger == reversedInteger)
19 System.out.println(originalInteger + " is a palindrome.");
20 else
21 System.out.println(originalInteger + " is not a palindrome.");
22 }
23}