Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Map;
- import java.util.SortedMap;
- import java.util.TreeMap;
- /**
- * @author deliveryninja
- *
- * Given a numeral from 1 to 3000 this will return the Roman
- * numberal equivalent.
- *
- * @param numeral
- * @return
- */
- public class Roman {
- public enum RomanNumeral{
- M(1000),
- CM(900),
- D(500),
- CD(400),
- C(100),
- XC(90),
- L(50),
- XL(40),
- X(10),
- IX(9),
- V(5),
- IV(4),
- I(1);
- private int value;
- RomanNumeral(int value){
- this.value = value;
- }
- public int getIntegerValue() {
- return value;
- }
- }
- public String romanize(int numeral) {
- StringBuffer result = new StringBuffer();
- for(RomanNumeral romanNumeral : RomanNumeral.values()){
- while(numeral >= romanNumeral.getIntegerValue()){
- result.append(romanNumeral);
- numeral -= romanNumeral.getIntegerValue();
- }
- }
- return result.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment