Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Class pallindrome 1/2

/*
* ashking13th@gmail.com
* javaprogramsbyashking13th.blogspot.in
* ashkingjava.blogspot.in
*
* QUESTION
*
* Design a program in java to check whether a number
* is a pallindrome number or not.
* A pallindrome number is a number is a number which is
* identical to its reverse.
* eg, 121,212,etc.
*/
import java.io.*;
public class pallindrome
{
public int reverse(int n) throws IOException
//method to create reverse of a number
{
int m=n;
//creating dummy variable
int r=0;
int s=0;
while(m>0)
//loop condition
{
r=m%10;
//last digit extraction
s=(s*10)+r;
//creating reverse number
m=m/10;
//updating loop variable
}
return s;
//returning reverse of a number
}
public void main() throws IOException
/*
* method to check if a number is pallindrome
*/
{
DataInputStream d=new DataInputStream(System.in);
System.out.println("enter the number");
//inputing the number
int n=Integer.parseInt(d.readLine());
int s= reverse(n);
//calling reverse function
if(s==n)
/*
* comparing reverse of number to original number and
* displaying message accordingly.
*/
Mar 25, 2014 3:27:17 PM
Class pallindrome (continued) 2/2
{
System.out.println("Number is pallindrome");
}
else
{
System.out.println("Number is not a pallindrome");
}
}
//end of main
}
//end of clss
Mar 25, 2014 3:27:17 PM

You might also like