Your Ad Here

Posted By

zeljic on 10/29/09


Tagged

roman numerals arabic


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

zeljic


Arabic to Roman numerals


 / Published in: Java
 

  1. public static String ArabicToRoman(int aNumber){
  2.  
  3. if(aNumber < 1 || aNumber > 3999){
  4. return "-1";
  5. }
  6.  
  7. int[] aArray = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
  8. String[] rArray = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
  9. String rNumber = "";
  10.  
  11. for(int i=0; i<aArray.length; i++){
  12. while(aNumber >= aArray[i]){
  13. rNumber += rArray[i];
  14. aNumber -= aArray[i];
  15. }
  16. }
  17.  
  18. return rNumber;
  19. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: zeljic on March 8, 2010

Original on: http://findwayout.com/20/arabic-to-roman-numerals-in-java/

You need to login to post a comment.