LeetCode -- Integer to Roman

Source: Internet
Author: User

Given an integer, convert it to a roman numeral.

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

Given an integer, convert it to a Roman number.

The input value can be between 1 and 3999.

Is a conversion rule.

1 2 3 4 5 6 7 8 9
I II III IV V VI VII VIII IX
10 20 30 40 50 60 70 80 90
X XX XXX XL L LX LXX LXXX XC
100 200 300 400 500 600 700 800 900
C CC CCC CD D DC DCC DCCC CM
The following program uses the example code to write the above table using if else. Of course, this course schedule is also regular. For example, the course starts with 1-3 and repeats. The last character is intercepted from 4-5, and the last character is added from 6 to 8.

Public static String intToRoman (int num) {StringBuffer buf = new StringBuffer (); int dddd = num/1000; int ddd = num % 1000/100; int dd = num % 1000%; int d = num % 1000% 100% 10; for (int I = 0; I
 
  
See this http://www.mathsisfun.com/roman-numerals.html for conversion rules for integers and Roman numerals.

Related Article

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.