I need to write a recursive method that displays a non negative integer with commas in the correct locations. For example, it should display:  20131 as 20,131.

I need to write a program to test the recursive method. Using Boolean value to distinguish the first recursive copy from the remaining ones.

Show the output for the 3 separate numbers: 43, 648         148, 348, 245          349
Who is Participating?
robthewolfConnect With a Mentor Commented:
ok, i just thought it was strange that you said that it needed to be recursive.
in that case you need to look at the Java api for the number formatters.
you can specify a format and it will output the number as a string according to that format.  have a look at these:

and some simple explained examples of how to use them here:

no need to reinvent the wheel, most things like this are handled in the api somewhere, dont be afraid to look for them ;)

Is this academic? If so please try to do it yourself and post questions and code when you get stuck.  No one will give you the answer if this is academic work that you are supposed to do yourself.  If it is not academic please explain why you need to do it recursively.
arhinAuthor Commented:
If you can help in another way then please go ahead. You need not handle it recursively. Its my own work. Its not academic
A number formatter will do exactly what the asker wants to achieve and very simply.  I have given plenty of resources and examples on other sites for the asker to implement what they need.  Given the askers comment that it does not have be recursive I feel that I have answered this question satisfactorily.
I am interested in the outcome, mainly to understand what was wrong with my suggestion, or alternatively to see that the asker understands how my suggestion will solve their problem.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.