Arabic to Roman Numerals in JAVA
public static String ArabicToRoman(int aNumber){
if(aNumber < 1 || aNumber > 3999){
return "-1";
}
int[] aArray = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
String[] rArray = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
String rNumber = "";
for(int i=0; iwhile(aNumber >= aArray[i]){
rNumber += rArray[i];
aNumber -= aArray[i];
}
}
return rNumber;
}
Comments
Post a Comment