Understanding this recursion

Hi, could you please help me understand the following case.

I wrote a method to convert numbers to roman numerals, I insert all the characters into a string variable but the output of the string comes out as the first one character. This is a recursive method and I know all the letters been inserted correctly as when I type system.out.print(roman), it prints all the characters but in a reverse order.

I curious to know why is that happen and could you please tell me how to reverse it.

Here is a piece of my code:

---------------------------------------------------------------------

public static String nums2Rom (int a){

String roman = "";

if (a >=1000){

roman+='M';

int2Rom (a-1000);

return roman+'M';}

if (a >=500 && a<1000){

roman+='D';

int2Rom (a-500);}

//...

//and ends like this:

if (a == 0) {

return roman;

}

else{

return roman;

//Thank you.

You right it is not the same I've changed names and

other things, I didn't understand Omirio's solution but appreciate it anyway.

I have an alternative method I've written..

I know it's long but I really appreciate if you could help me figure out why instead of getting the length of each digit I'm getting the length of the first digit. For ex. if I put 4321 it comes out as: MMMMCCCCXXXXIIII.

-------------------------------------------------------------------------

public static String int2Rom (int a){

String numstr = (String) ""+a;

int digs = numstr.length()-1; // set the length of the number.

int num=0;

switch (digs) {

case 3:num = a/1000; break;

case 2: num = a/100; break;

case 1: num = a/10; break;

case 0: num = a/1; break;

}

if (a == 0) //base case.

return "";

else {

return converter (digs, num, a);

}

}

// ------question 4. ----- Helper method ----.

public static String converter (int digs, int num, int a){

String array [] [] = {{"V","I"},{"L","X"},{"D","C"},{"5M","M"}};

String roman = "";

int bs;

if (num ==0) //base case

return num2Rom (a/10);

else{

if (num >=5){

bs = 0;

roman+= array [digs] [bs];

num-=5;

converter (digs, num, a);

}

if (num <5){

bs = 1;

System.out.print (array [digs] [bs]);

num--;

converter (digs, num, a);

}}

return roman;

}

}