Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java convert to roman numerals

import java.util.TreeMap;

public class RomanNumber {

    private final static TreeMap<Integer, String> map = new TreeMap<Integer, String>();

    static {

        map.put(1000, "M");
        map.put(900, "CM");
        map.put(500, "D");
        map.put(400, "CD");
        map.put(100, "C");
        map.put(90, "XC");
        map.put(50, "L");
        map.put(40, "XL");
        map.put(10, "X");
        map.put(9, "IX");
        map.put(5, "V");
        map.put(4, "IV");
        map.put(1, "I");

    }

    public final static String toRoman(int number) {
        int l =  map.floorKey(number);
        if ( number == l ) {
            return map.get(number);
        }
        return map.get(l) + toRoman(number-l);
    }

}
Comment

PREVIOUS NEXT
Code Example
Java :: android studio change image on button click 
Java :: Create a button that redirects to another activity in android studio 
Java :: java 8 find in list by property 
Java :: java download file from url 
Java :: Islands count leetcode 
Java :: replace substring at index java 
Java :: java how to make a number 
Java :: what method is use for getting the index position of a character of a string in java 
Java :: java distinct by key 
Java :: string length solidity 
Java :: materialbutton remove shadow xml 
Java :: android zoom animation 
Java :: UTC in Java 
Java :: print values of bst java 
Java :: get preference value android 
Java :: java collapse string array 
Java :: validate date java 
Java :: queue implementation in java using arraylist 
Java :: java Write a program to reverse an array or string 
Java :: How to efficiently shift a linked list by k positions, in Java? 
Java :: spring scheduled 
Java :: reverse int array java 
Java :: PathProviderPlugin.java uses unchecked or unsafe operations. 
Java :: findviewbyid in kotlin Just using id name . 
Java :: from date to string 
Java :: jdbc interface 
Java :: java run code at interval 
Java :: parameterized constructor 
Java :: all installed java 
Java :: nested list java 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =