标签:
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
把十进制转为罗马数
public class Solution { private int[] val = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 }; private String[] syb = new String[] { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" }; public String intToRoman(int num) { StringBuilder roman = new StringBuilder(); int i = 0, k; while (num > 0) { k = num / val[i]; while (k-- > 0) { roman.append(syb[i]); num -= val[i]; } i++; } return roman.toString(); }
标签:
原文地址:http://www.cnblogs.com/zxqstrong/p/5275028.html