Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Java int to roman

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 :: java check if number is even 
Java :: java double to long 
Java :: lombok ignore getter e setter 
Java :: Card view implement 
Java :: javafx tableview remove all rows 
Java :: return boolean value from stream 
Java :: groovy base64 encode 
Java :: ranfom number between 1 to 100 java 
Java :: Thread inline ajva 
Java :: How to turn off darkmode for my app in android studio 
Java :: spigot how to make an inventory 
Java :: spring boot id auto generated 
Java :: how to print a 2d array in java 
Java :: JFrame Exit oon close Java15 
Java :: set color of text for jlabel 
Java :: add label gui jframe 
Java :: bukkit runnable 
Java :: how to install java 11 jdk on ubuntu 20.04 
Java :: centos install openjdk 11 
Java :: Spigot API inventory close 
Java :: where is java installed in ubuntu 
Java :: iterate over string java 
Java :: coding fill method java 
Java :: react native webview debug network 
Java :: how to cnahe chat format in bukkit 
Java :: How to execute Shell Commands with Java and print the output directly while executing the command 
Java :: right click java 
Java :: initialize hashset java 
Java :: list java processes 
Java :: How to find the Levenshtein distance between two strings of characters, in Java? 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =