Java Integer to intToRoman(int i)

Here you can find the source of intToRoman(int i)

Description

set command line for Runtime.exec() depending on operation system R_BATCH is set in chg.properties and loaded with programm start R_BATCH contains absolute pathname to batch file inside the batchfile R batch is called

License

Open Source License

Declaration

public static String intToRoman(int i) 

Method Source Code

//package com.java2s;
/**//from   ww  w.ja  v  a  2s . c  om
 * @name Utils.java
 *
 *
 * @author Katrin Tebel <tebel at molgen.mpg.de>
 * @author Wei Chen
 *
 * The contents of this file are subject to the terms of either the GNU General
 * Public License Version 2 only ("GPL") or the Common Development and
 * Distribution License("CDDL") (collectively, the "License"). You may not use
 * this file except in compliance with the License. You can obtain a copy of the
 * License at http://www.netbeans.org/cddl-gplv2.html or
 * nbbuild/licenses/CDDL-GPL-2-CP. See the License for the specific language
 * governing permissions and limitations under the License. This program is
 * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE.
 */

public class Main {
    /**
     * set command line for Runtime.exec() depending on operation system R_BATCH
     * is set in chg.properties and loaded with programm start R_BATCH contains
     * absolute pathname to batch file inside the batchfile R batch is called
     */
    public static String intToRoman(int i) {
        if (i > 50) {
            return intToRoman(i - 50);
        }

        String roman = "";

        if (i >= 10) {
            for (int j = (int) Math.ceil(i / 10); j > 0; j--) {
                i -= 10;
                roman += "X";
            }

        }
        if (i == 9) {
            return (roman += "IX");
        }

        if (i >= 5) {
            roman += "V";
            i -= 5;

            for (int d = i; d > 5; d--) {
                i -= 1;
                roman += "I";
            }

        }
        if (i == 4) {
            return (roman += "IV");
        }
        for (int d = i; d > 0; d--) {
            roman += "I";
        }

        return roman;
    }
}

Related

  1. intToPrefixCoded(final int val, final int shift, final char[] buffer)
  2. intToRegisters(int v)
  3. intToRGB(int color)
  4. IntToRGB(int rgbInt)
  5. intToRgbComponents(int rgb)
  6. intToRoman(int value)
  7. intToScaleString(final int number, final int scale)
  8. intToShort(final int value)
  9. intToSlider(final int min, final int max, final int value)