0% found this document useful (0 votes)
90 views2 pages

Pallindrome PDF

This program defines a method to reverse a number and return the reversed number. It then defines a main method that takes user input for a number, calls the reverse method to get the reversed number, and compares the reversed number to the original to check if it is a palindrome - a number that is the same when reversed, such as 121. It prints whether the number is or is not a palindrome based on the comparison.

Uploaded by

AMRENDRA SINGH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views2 pages

Pallindrome PDF

This program defines a method to reverse a number and return the reversed number. It then defines a main method that takes user input for a number, calls the reverse method to get the reversed number, and compares the reversed number to the original to check if it is a palindrome - a number that is the same when reversed, such as 121. It prints whether the number is or is not a palindrome based on the comparison.

Uploaded by

AMRENDRA SINGH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Class pallindrome 1/2

/*
* [email protected]
* 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