# recursion problem

• 01-05-2011, 02:32 PM
Yakg
recursion problem
Hi I have this problem with a recursion method which supposed to convert numbers into roman numerals.

I am giving a number, and the num variable I wrote should change by the length of the number, so if it's a 4digit number the given number will be divided by 1000 ,3digits /100.. .
From some reason it does that for the first time and then the number stay's the same.

So my output for 4321 is: MMMMCCCCXXXXIIII.
Any ideas what could be the problem?

Here's part of the code (one method out of two):

public static String num2Roms (int a){
String numstr = (String) ""+a;
int digs = numstr.length()-1; // set the length of the number.
int num;
switch (digs) {
case 0: num = a/1; break;
case 1: num = a/10; break;
case 2: num = a/100; break;
default:num = a/1000; break;
}
if (a == 0) //base case.
return "";
else {
return converter (digs, num, a);
}
}

//thanks.
• 01-05-2011, 03:00 PM
KevinWorkman
When posting code, make sure it's formatting using the CODE tags. It should also be in the form of an SSCCE.
• 01-05-2011, 03:45 PM
Yakg
I think it's got to do with
the switch statement, it doesn't change the number..