Llevo muy poco en java, avisadme si veis algún error o algo mejorable, a ver que os parece:
import java.util.*;
public class Hello {
public static String repeatString
(String sText,
int iTimes
){ return new String(new char[iTimes
]).
replace("\0", sText
); }
public static String decimalToRomano
(int iNum
) { int iTmp= 0, i= 1;
{
{"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"},
{"X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"},
{"C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}
};
if (iNum > 0){
for (int x=0; x<3; x++){
iTmp=iNum % (i * 10);
if (iTmp != 0)
sRet= sRDigit[x][(iTmp / i) -1] + sRet;
iNum -= iTmp;
if (iNum == 0)
return sRet;
i *= 10;
};
sRet= repeatString("M", iNum / 1000) + sRet;
};
return sRet;
}
public static void main
(String args
[]) { System.
out.
println("Dame un numero mayor que cero para convertirlo a un numero romano:");
int iMyNum
= new Scanner
(System.
in).
nextInt(); System.
out.
println("El numero "+ iMyNum
+ " en romano es: " + decimalToRomano
(iMyNum
)); }
}
DoEvents!