-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegertoRoman.java
More file actions
32 lines (27 loc) · 962 Bytes
/
IntegertoRoman.java
File metadata and controls
32 lines (27 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.mirraico.leetcode;
public class IntegertoRoman {
public String intToRoman(int num) {
String one[] = new String[] {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
String ten[] = new String[] {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
String hundred[] = new String[] {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
String thousand[] = new String[] {"", "M", "MM", "MMM"};
String ans;
ans = one[num % 10];
if((num = num / 10) == 0) {
return ans;
}
ans = ten[num % 10] + ans;
if((num = num / 10) == 0) {
return ans;
}
ans = hundred[num % 10] + ans;
if((num = num / 10) == 0) {
return ans;
}
ans = thousand[num % 10] + ans;
return ans;
}
public static void main(String[] args) {
System.out.println(new Solution().intToRoman(11));
}
}