hi, i was wondering if anyone could help me out? i have this project in my java class where i need to format an integer to a string with commas (ex:1000000->1,000,000) using recursion. I've tried it for 4 class periods and i just can't figure it out. If you feel guilty by giving me just the answer feel free to give me a tutorial on recursion so that i get the answer and understand it better.
I figured some people woudl like to see what i have now.

static String insertCommas(int num)
{
         int rem=0;
         String str="";
        if(num<1000)
                        {
                        str+=num;  
                        return str;
                        }
                        else
                        {
                        str+=num+",";
                        insertCommas(num%1000);
                        }
                       return str;
}

why complicate things?

import java.text.NumberFormat;

.......

static String insertCommas(int num)
{
		 return NumberFormat.getInstance().format(num);
}

I can help you, but I have school right now, but after I'll help you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.