Wednesday, July 1, 2015

Palindrome Program in Java

  1. palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. Allowances may be made for adjustments to capital letters, punctuation, and word dividers.


import java.util.*;

public class Palindrom
{
public static void main(String [] args)
{
Scanner scn =new Scanner (System.in);
System.out.println("enter no. to check palindrom or not");
int n=scn.nextInt();
int a=n, b=n,rev=0;
while(a>0)
{
n=a%10;
rev=rev*10+n;
a=a/10;
}
if(rev==b)
{
  System.out.println("number is palindrom");
}
else
{
   System.out.println("no. is not palindrom");
}


}

}

0 comments:

Post a Comment