Java Integer to Roman IntegerToRoman(int n)

Here you can find the source of IntegerToRoman(int n)

Description

Integer To Roman

License

Open Source License

Declaration

public static String IntegerToRoman(int n) 

Method Source Code

//package com.java2s;
/*// w  w  w . ja va 2 s.c  o m
  * Copyright (C) 2012 Viettel Telecom. All rights reserved.
  * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  */

public class Main {
    public static String IntegerToRoman(int n) {
        String roman = "";
        int repeat;
        int magnitude[] = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 };
        String symbol[] = { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" };
        repeat = n / 1;
        for (int x = 0; n > 0; x++) {
            repeat = n / magnitude[x];
            for (int i = 1; i <= repeat; i++) {
                roman = roman + symbol[x];
            }
            n = n % magnitude[x];
        }
        return roman;
    }
}

Related

  1. integerToRoman(int n)