Integer to Roman
Given an integer, convert it to a roman numeral.
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
题目比价简单,也好理解。不过罗马数字中最主要的是4的表示,代码如下:
public class Solution {
public String intToRoman(int num) {
int[] v = new int[]{1000,900,500,400,100,90,50,40,10,9,5,4,1};
String[] k = new String[]{"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
int i = 0;
String s = "";
while(num != 0){
while(num >= v[i]){
s += k[i];
num -= v[i];
}
i++;
}
return s;
}
}