Number Palindrome or not

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward.  
A program to find the given number is palindrome or not
 //Program palindrom or not  
 import java.io.*;  
 class Pallin{  
 public static void main(String arg[])throws IOException  
 {  
 int a=0,ts=0,i=0,palli=0;  
 DataInputStream dip=new DataInputStream(System.in);  
 System.out.println("\n");  
 System.out.println("\t*-- PROGRAM TO FIND NUMBER PALINDROME OR NOT --*");  
 System.out.print("\t");  
 for( i=0;i<17;i++)  
 {System.out.print("_ _");}  
 System.out.println("\n");  
 System.out.println("Please enter 3 digit values");  
 System.out.print("Enter the values= ");  
 a=Integer.parseInt(dip.readLine());  
 ts=a;  
 while(ts>0)  
 {  
 i=ts%10;  
 palli=(palli*10)+i;  
 ts=ts/10;  
 }  
 if(a==palli)  
 System.out.println(palli+" is palindrome");  
 else  
 System.out.println(a+" is not palindrome");  
 }}  
the output of the above program is given below:
Next program is to find the palindrome numbers between two limits
 //Program find palindrom numbers  
 import java.io.*;  
 class Pallinck{  
 public static void main(String arg[])throws IOException  
 {  
 int ts,i,palli=0,flag=0;  
 int l,u,n,count=0;  
 DataInputStream dip=new DataInputStream(System.in);  
 System.out.println("\n");  
 System.out.println("\t*-- PROGRAM TO FIND PALINDROME NUMBER--*");  
 System.out.print("\t");  
 for( i=0;i<14;i++)  
 {System.out.print("_ _");}  
 System.out.println("\n");  
 System.out.print("Enter lower limit= ");  
 l=Integer.parseInt(dip.readLine());  
 System.out.print("Enter upper limit= ");  
 u=Integer.parseInt(dip.readLine());  
 System.out.println();  
 System.out.println("Palindrom numbers between "+l+" and "+u);  
 for(i=l;i<u;i++){  
 palli=0;  
 ts=i;  
 while(ts>0){  
 n=ts%10;  
 palli=(palli*10)+n;  
 ts=ts/10;  
 }  
 if(i==palli){  
 count++;  
 System.out.print(i+" ");  
 flag=1;  
 }  
 }  
 System.out.println("\n");  
 if(flag==0)  
 System.out.println("No pallindrom numbers found!!!");  
 else  
 System.out.println("Found "+count+" pallindrom numbers");  
 }}  
Output :

No comments: