A palindromic number is a number which remains same when all it's digits are reversed.
Here is a program in java that asks the user to input a number and check whether the number is palindrome or not.
Source Code :-
/*****************************************************************************/
/*PROGRAM TO CHECK WHETHER A NUMBER
* INPUTTED BY THE USER IS PALINDROME OR NOT
*/
import java.util.Scanner;
public class test66 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("ENTER A NUMBER");
int num=s.nextInt();
int cpy_num=num;
int rev=0;
while(num!=0)
{
rev=rev*10+num%10;
num/=10;
}
if(rev==cpy_num)
System.out.println("THE NUMBER YOU ENTERED IS A PALINDROME");
else
System.out.println("THE NUMBER YOU ENTERED IS NOT A PALINDROME");
}
}
/*******************************************************************************/
Output :-
ENTER A NUMBER
12344321
THE NUMBER YOU ENTERED IS A PALINDROME
No comments:
Post a Comment