Java code to check whether give number is palindrome number or not

Palindrome program in java

import java.io.*;

class Test {
    
     public static void main(String[] args) throws IOException {
         
          int num,r,sum=0,temp;
          System.out.println("Enter a number:");
          BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
          num=Integer.parseInt(br.readLine());
          temp=num;

          while(num!=0){
              r=num%10;
              num=num/10;
              sum=sum*10+r;
          }

          if(temp==sum)
              System.out.println(temp+" is a palindrome");
          else
              System.out.println(temp+" is not a palindrome");
     }

No comments: