1. Member
Join Date
Dec 2010
Posts
59
Rep Power
0

## 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.

2. When posting code, make sure it's formatting using the CODE tags. It should also be in the form of an SSCCE.

3. Member
Join Date
Dec 2010
Posts
59
Rep Power
0

## I think it's got to do with

the switch statement, it doesn't change the number..

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•