Write a Java program to input a number and check if it is palindrome or not

 Write a program  in Java to input a number and check if it is  palindrome or not

Palindrome : palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam or racecar.

import java.util.Scanner;

public class Palin {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.print("Enter A Number : ");
int num =sc.nextInt();
int rev=0,ldigit;
int temp=num;
while (temp!=0) {
ldigit=temp%10;
rev=rev*10+ldigit;
temp=temp/10;
}
if (num==rev) {
System.out.println(num +" is Palindrome");
} else {
System.out.println(num +" is not Palindrome");
}
}
}


 

OUTPUT

1. 
     Enter a Number : 123454321
     123454321 is Palindrome

2. 
     Enter a Number : 345232
     345232 is not Palindrome



Share:

0 Comments:

Post a Comment

Pageviews