package com.tutorial4u;
import java.util.Scanner;
public class PalindromeNumber {
public static void main(String[] args) {
int num, reverse=0,temp;
System.out.print("Please enter any number to check palindrome : ");
Scanner sc = new Scanner(System.in);
num = sc.nextInt();
temp = num;
while(num!=0){
reverse = reverse*10;
reverse=reverse+num%10;
num= num/10;
}
if(temp == reverse){
System.out.println("Given number is palindrome");
}else{
System.out.println("Given number is not palindrome");
}
}
}
Output:
Please
enter any number to check palindrome : 121
Given
number is palindrome
No comments:
Post a Comment