MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / Solution

Class Solution

src/com/blankj/medium/_0012/Solution.java:11–25  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2018/01/25 desc :

Source from the content-addressed store, hash-verified

9 * </pre>
10 */
11public class Solution {
12 public String intToRoman(int num) {
13 String M[] = {"", "M", "MM", "MMM"};
14 String C[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
15 String X[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
16 String I[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
17 return M[num / 1000] + C[(num % 1000) / 100] + X[(num % 100) / 10] + I[num % 10];
18 }
19
20 public static void main(String[] args) {
21 Solution solution = new Solution();
22 System.out.println(solution.intToRoman(621));// DCXXI
23 System.out.println(solution.intToRoman(348));// CCCXLVIII
24 }
25}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected