Preciso fazer um projeto para converter algarismos romanos em decimais e encontrei o seguinte método:
/**
* Author: Francisco Edmundo
*
**/
private int traduzirNumeralRomano(String texto) {
int n = 0;
int numeralDaDireita = 0;
for (int i = texto.length() - 1; i >= 0; i--) {
int valor = (int) traduzirNumeralRomano(texto.charAt(i));
n += valor * Math.signum(valor + 0.5 - numeralDaDireita);
numeralDaDireita = valor;
}
return n;
}
private double traduzirNumeralRomano(char caractere) {
return Math.floor(Math.pow(10, "IXCM".indexOf(caractere))) + 5 * Math.floor(Math.pow(10, "VLD".indexOf(caractere)));
}
Já fiz alguns testes e ele está funcionando, porém, não entendi exatamente o que ele faz e os parâmetros utilizados. Alguém pode me ajudar a “traduzir” esse código?
