Tuesday, 29 August 2017

How find given number or string is palindrome or not in java program

Java program to find that given number or string is palindrome or not

Program

import java.util.Scanner;
class palindrome
{
          public static void main(String args[])
          {
                   int r,sum=0,temp,n;
                   Scanner in = new Scanner(System.in);
                   System.out.println("Enter to any number");
                   n=in.nextInt();
                   temp = n;
                             while(n>0){
                                      r=n%10;
                                      sum=(sum*10)+r;
                                      n=n/10;
                             }
                   if(temp==sum)
                             System.out.println("number is palindrome");
                   else
                             System.out.println("number is not palindrome");

                   }        }

Output

palindrome  Core Java


0 comments:

Post a Comment