A number (or a word) is called palindrome if it may be read in the same way from left to right as right to left (e.g. 131 and 56965). Write a Java application that reads from the user a positive integer consists of exactly 5 digits. Then separates the integer into its individual digits and prints a message indicating if this integer is palindrome or not. The program should print an error message if the number is not positive and not composed of 5 digits. Hint: Use % 10 in order to extract the last digit of an integer and / 10 in order to eliminate the last digit of an integer. For example, 942 % 10 = 2 and 942 / 10 =94. Sample run1: Enter a positive integer (5 digits): -12345 The number should be positive and of 5 digits Sample run2: Enter a positive integer (5 digits): 123 The number should be positive and of 5 digits Sample run3: Enter a positive integer (5 digits): 12321 12321 is a palindrome Sample run4: Enter a positive integer (5 digits): 12345 12345 is not palindrome
A number (or a word) is called palindrome if it may be read in the same way from left to
right as right to left (e.g. 131 and 56965).
Write a Java application that reads from the user a positive integer consists of exactly 5 digits.
Then separates the integer into its individual digits and prints a message indicating if this
integer is palindrome or not.
The program should print an error message if the number is not positive and not composed of 5
digits.
Hint: Use % 10 in order to extract the last digit of an integer and / 10 in order to eliminate
the last digit of an integer. For example, 942 % 10 = 2 and 942 / 10 =94.
Sample run1:
Enter a positive integer (5 digits): -12345
The number should be positive and of 5 digits
Sample run2:
Enter a positive integer (5 digits): 123
The number should be positive and of 5 digits
Sample run3:
Enter a positive integer (5 digits): 12321
12321 is a palindrome
Sample run4:
Enter a positive integer (5 digits): 12345
12345 is not palindrome
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images