

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Here is one way to produce a palindrome from any integer: if the integer is a palindrome, stop. Otherwise, invert the digits in the integer and add 2, continuing until you get a palindrome (which you always will). For example suppose you start with 108. The sequence of numbers you’d get using the above process would be: 108, 803, 310, 15 (notice the leading zero is dropped when inverting), 53, 37, 75, 59, 97, 81, 20, 4. This took 11 steps.
Write a program, NumericPal, which asks for input from the user – a series of positive integers with two or more digits – and for each, displays the palindrome it produces (using the method described in the previous paragraph), and the number of steps it took to produce the palindrome. The expected display format is given in the example on the back of this sheet.
Each input should produce two lines of output (in a single dialog box). Use a sentinel to signal end of input. You must create and utilize at least two methods, isPalindrome() — to determine whether or not a number is a palindrome, and ReverseDigits() — which reverses the digits in a number. The isPalindrome() method should make use of the ReverseDigits() method, then compare the digits in the original with those in the reversed number.
Continued on reverse.
MAT 2170: Laboratory 7 2
Sample Execution:
input: output (in a dialog box): 108 The Palindrome generated for 108 is 4. This took 11 steps.
342 The Palindrome generated for 342 is 8. This took 13 steps.
1002 The Palindrome generated for 1002 is 111. This took 9 steps.
999 The Palindrome generated for 999 is 999. This took 0 steps.
-1 Thank you for using my program. Bye.
When you have completed the lab: