Integer to Roman Java solutions

Source: Internet
Author: User

Given an integer, convert it to a Roman numeral.

Input is guaranteed to being within the range from 1 to 3999.

Basic characters I V X L C D M
The corresponding Arabic numerals are expressed as 1 5 10 50 100 500 1000
    1. The same number ligatures, the number represented is equal to the number of these numbers added, such as: ⅲ= 3;
    2. The small number is on the right side of the large number, and the number represented is equal to the number added to the number, such as: ⅷ= 8;ⅻ= 12;
    3. Small numbers, (limited to Ⅰ, X, and C) on the left side of the large number, represented by the number equal to the number of large reduction numbers obtained, such as: ⅳ= 4;ⅸ= 9;
    4. In normal use, the number of ligatures cannot be repeated more than three times. (Exception of four O'Clock "IIII" on the dial)
    5. Draw a horizontal line over a number to indicate that the number is enlarged 1000 times times.
1  Public classSolution {2      PublicString Inttoroman (intnum) {3String [] i = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};4String [] x = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};5String [] C = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};6String [] m = {"", "M", "MM", "MMM"};7         8         return(m[num/1000] + c[(num%)/100] + x[(num%)/10] + i[num% 10]). Trim ();9     }Ten}

The China bit is answer.

Integer to Roman Java solutions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.