Write a program to find whether given Number is Palindrome or Not
import java.util.Scanner; public class PalindromeOfNumber { public static void main (String[] args) { int mod=0; int c=0; int d=0; int num1=0; System.out.println("Enter a number:"); Scanner sc=new Scanner(System.in); int num=sc.nextInt(); num1=num; while(num>0) { mod=num%10; c=c+mod; num=num/10; d=mod+d*10; } if(num1==d) { System.out.println("The given number "+num1+" is palindrome"); } else { System.out.println("The given number "+num1+" is not palindrome"); } } } OUTPUT: Enter a number: 1523 The given number 1523 is not palindrome
No comments:
Post a Comment