/* * 12.Integer to Roman * 2016-4-14 by Mingyang * 这里我先忘掉了50和40,然后在499还是490之间纠结了一会 * 另外if判断句里面 if(num>=array[i])是大于等于不是只有大于,不然9过不去 */ public static String intToRoman(int num) { String res=""; if(num<=0) return res; int[] array={1,4,5,9,10,40,50,90,100,400,500,900,1000}; String[] str={"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"}; StringBuffer sb=new StringBuffer(); while(num>0){ for(int i=array.length-1;i>=0;i--){ if(num>=array[i]){ int tem=num/array[i]; while(tem>0){ sb.append(str[i]); tem--; } num=num%array[i]; } } } return sb.toString(); }