import java.util.Scanner; /** * Roman numerals * I 1 * V 5 * X 10 * L 50 * C 100 * D 500 * M 1000 * * Numbers are written in decreasing value * Example: XII is 12, not IIX or IXI * * But there are special rules: * I can come before V or X IV = 4, IX = 9 * X can come before L or C XL = 40, XC = 90 * C can come before D or M CD = 400 CM = 900 */ public class Roman { public static String intToRoman(int n) { String ret = ""; int val = n; // dealing with the thousands case if(n > 1000) { int m = val / 1000; for(int i =0;i=900) { ret += "CM"; val -= 900; } // 600-800 range if(val>=600) { int c = (val - 500)/100; for(int i =0;i=500) { ret += "D"; val -= 500; } // 400 special case if(val>=400) { ret +="CD"; val -= 400; } // 100 - 300 range if(val>=100) { int x = (val - 100)/100; for(int i =0;i=90) { val -=90; ret += "XC"; } if(val>=50) { ret += "L"; int L=(val-50)/10; for(int i =0;i=40) { ret += "XL"; val -= 40; } if(val>=10) { int x = (val - 10)/10; for(int i =0;i5){ int c = (val - 5); for(int i =0;i