Integer to Roman

Given an integer, convert it to a roman numeral.

Input is guaranteed to be within the range from 1 to 3999.
数字转换为罗马数字,而且还限制了最大值,所以用一个很取巧的方式。
	    public String intToRoman(int num) {
	        String result = "";
	        String[] ge = {"","I", "II","III", "IV","V","VI","VII", "VIII","IX"};
	        String[] hen = {"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
	        String[] he = {"","C","CC","CCC","CD", "D","DC","DCC","DCCC","CM"};
	        String[] thr = {"","M","MM","MMM"};
	        int[] i = {0,0,0,0};
	        int c = num;
	        for(int j = 0;j<4;j++){
	        	i[j] = c%10;
	        	c /= 10;
	        }
	       result = thr[i[3]]+he[i[2]]+hen[i[1]]+ge[i[0]];
	        return result;
	    }

关于罗马数字 http://baike.baidu.com/link?url=1BTnMQM8UpftRdCc9X_Y_fupzMgCJbP_26OM4CAmLJFUAD1prEvnGO8S9jssOyopNYPididMx7Yjsq132xua4_

猜你喜欢

转载自plan454.iteye.com/blog/2187827