Write a program that takes an integer on the command line


Write a program called Assg4.java to solve the following problem.

Write a program to solve the following problem. Given a small integer (e.g. 78), we can reverse it (giving 87) and add the reverse to itself (giving 165). If this is performed repeatedly then usually a number that is a palindrome is eventually produced.

Write a program that takes an integer on the command line, checks that it is not negative or bigger than 200 (in which case a suitable message should be printed and no computation performed) and then prints it out followed by every number that is produced during repeatedly performing the above operation until a palindromic number is produced. A typical run should be as follows.

% java Assg4 78
78
165
726
1353
4884
The number 78 took 4 steps to reach a palindrome.

In addition, your program should terminate with an error message if more than 10 steps are taken, as follows.

% java Assg4 89
89
187
968
1837
9218
17347
91718
173437
907808
1716517
8872688
The number 89 takes more than 10 steps to reach a palindrome.

[Note that you may safely ignore the possibility of integer overflow in this assignment, given the size and iteration limits imposed above.]

Hint: One way to proceed is to write static methods to convert an int to a String and vice-versa first, and test them. Then write a static method to test whether or not a String is a palindrome, and test it. Now use these methods to help solve the problem. 

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Write a program that takes an integer on the command line
Reference No:- TGS01155617

Expected delivery within 24 Hours