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}
1import java.util.Scanner;
2
3public class Palindrome
4{
5 public static void main(String args[])
6 {
7 int num,temp,reverse=0;
8 Scanner input=new Scanner(System.in);
9 num=in.nextInt();
10 temp=num;
11 //code to reverse the number
12 while(temp!=0)
13 {
14 int d=temp%10; //extracts digit at the end
15 reverse=reverse*10+d;
16 temp/=10; //removes the digit at the end
17 }
18 // 'reverse' has the reverse version of the actual input, so we check
19 if(reverse==num)
20 {
21 System.out.println("Number is palindrome");
22 }
23 else
24 {
25 System.out.println("Number is not palindrome");
26 }
27 }
28}