public class Solution {
public String intToRoman(int num) {
StringBuilder stringBuilder = new StringBuilder("");
int c = num/1000;
num %= 1000;
for(int i = 0; i < c; i++){
stringBuilder.append("M");
}
c = num / 100;
num %= 100;
switch (c) {
case 9:
stringBuilder.append("CM");
break;
case 8:
stringBuilder.append("DCCC");
break;
case 7:
stringBuilder.append("DCC");
break;
case 6:
stringBuilder.append("DC");
break;
case 5:
stringBuilder.append("D");
break;
case 4:
stringBuilder.append("CD");
break;
case 3:
stringBuilder.append("CCC");
break;
case 2:
stringBuilder.append("CC");
break;
case 1:
stringBuilder.append("C");
break;
default:
break;
}
// I(1),V(5),X(10),L(50),C(100),D(500),M(1000)
c = num /10;
num %= 10;
switch (c) {
case 9:
stringBuilder.append("XC");
break;
case 8:
stringBuilder.append("LXXX");
break;
case 7:
stringBuilder.append("LXX");
break;
case 6:
stringBuilder.append("LX");
break;
case 5:
stringBuilder.append("L");
break;
case 4:
stringBuilder.append("XL");
break;
case 3:
stringBuilder.append("XXX");
break;
case 2:
stringBuilder.append("XX");
break;
case 1:
stringBuilder.append("X");
break;
default:
break;
}
// I(1),V(5),X(10),L(50),C(100),D(500),M(1000)
switch (num) {
case 9:
stringBuilder.append("IX");
break;
case 8:
stringBuilder.append("VIII");
break;
case 7:
stringBuilder.append("VII");
break;
case 6:
stringBuilder.append("VI");
break;
case 5:
stringBuilder.append("V");
break;
case 4:
stringBuilder.append("IV");
break;
case 3:
stringBuilder.append("III");
break;
case 2:
stringBuilder.append("II");
break;
case 1:
stringBuilder.append("I");
break;
default:
break;
}
return stringBuilder.toString();
}
}