Java program to check whether a given number is palindrome or not

import java.util.*;

class palindrome  {
  public static void main(String s[] ){
  try{
  Scanner sc =new Scanner(System.in);
  System.out.println("Enter number");
  int num= sc.nextInt();
  int n = num;
  int rev=0;
  System.out.println("Number: ");
  System.out.println(" "+ num);
  while(num>0){
  int r=num%10;
  num=num/10;
  rev=rev*10+r;
 
  }
  System.out.println("After reversing the number: "+ " ");
  System.out.println(" "+ rev); 
  if(n == rev){
  System.out.print("Number is palindrome!");
  }
  else{
  System.out.println("Number is not palindrome!");
  }
  }
  catch(Exception e){
  System.out.println("Out of range!");
  }
  }
}

Comments