Posted by : Unknown
Sunday, 28 June 2015
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class palindrome
{
public static void main(String[] args)
{
try
{
System.out.print("Enter a number: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String num=br.readLine();
int no=Integer.parseInt(num);
int temp=no;
int digit=0,ld;
while(no!=0)
{
ld=no%10;
digit=digit*10+ld;
no=no/10;
}
if(temp==digit)
{
System.out.println("Palindrome number");
}
else
{
System.out.println("Not a palindrome number");
}
}
catch (IOException | NumberFormatException ex)
{
}
}
}
import java.io.IOException;
import java.io.InputStreamReader;
class palindrome
{
public static void main(String[] args)
{
try
{
System.out.print("Enter a number: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String num=br.readLine();
int no=Integer.parseInt(num);
int temp=no;
int digit=0,ld;
while(no!=0)
{
ld=no%10;
digit=digit*10+ld;
no=no/10;
}
if(temp==digit)
{
System.out.println("Palindrome number");
}
else
{
System.out.println("Not a palindrome number");
}
}
catch (IOException | NumberFormatException ex)
{
}
}
}
Output:
Enter a number: 123
Not a palindrome number
Not a palindrome number
Enter a number: 12321
Palindrome number
Palindrome number
Related Posts :
- Back to Home »
- Example program , Simple Program »
- Palindrome number program in java