branch14.org

 1 
       2 class Roman {
       3 
       4     public static void main(String[] s) {
       5 
       6         String[][] rdigits = {{"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"},
       7                               {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"},
       8                               {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"},
       9                               {"", "M", "MM", "MMM", "MMMM", "MMMMM", "MMMMMM", "MMMMMMM", "MMMMMMMM", "MMMMMMMMM"}};
      10 
      11         for(int i=0;i<s[0].length();i++) System.out.print(rdigits[s[0].length()-1-i][Integer.parseInt(s[0].substring(i, i+1))]);
      12 
      13         System.out.println();
      14 
      15     }
      16 
      17 }
      

duplicate all pages in acrobat

  • snippet type: algorithm
  • keywords: roman, decimal, conversion
  • language: java

this is just a very minimal approach vonverting decimal numbers to
roman numbers for numbers upto 9999.