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

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.5: A Closer Look: Loop Programming Techniques
Problem 14E
icon
Related questions
Question

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

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT