This Java program checks whether an input integer is a palindrome or not. A palindrome number is a number that remains the same when its digits are reversed.
Overall, this program correctly checks whether an input integer is a palindrome or not. However, it could be improved by handling the case where the user inputs a negative integer. In this case, the program would print out that the negative integer is not a palindrome, even though it technically is a palindrome when its absolute value is considered. A message should be added to handle this case.
import java.util.Scanner; class Palindrome_Number { public static void main (String[]args) { Scanner input = new Scanner(System.in); System.out.print("Enter The Digits :"); int num = input.nextInt(); int rev = 0, rem, temp; temp = num; while (num != 0) { rem = num % 10; rev = rev * 10 + rem; num /= 10; }; if (temp == rev) System.out.println (temp + " is Palindrome"); else System.out.println (temp + " is not Palindrome"); } }
Enter The Digits :68586 68586 is Palindrome Enter The Digits :67587 67587 is not Palindrome
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions