标签:sys pre java [] bsp convert eth rom span
描述
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
分析
无
代码
1 public class IntegerToRoman { 2 3 public static void main(String[] args) { 4 // TODO Auto-generated method stub 5 int num = 187; 6 System.out.println(intToRoman(num)); 7 } 8 9 public static String intToRoman(int num) { 10 int radix[] = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 }; 11 String symbol[] = { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" }; 12 String roman = ""; 13 for (int i = 0; num > 0; ++i) { 14 int count = num / radix[i]; 15 num %= radix[i]; 16 for (; count > 0; --count) 17 roman += symbol[i]; 18 } 19 return roman; 20 } 21 22 }
Integer to Roman LeetCode Java
标签:sys pre java [] bsp convert eth rom span
原文地址:https://www.cnblogs.com/ncznx/p/9195594.html