# Convert year to roman numeral.

• 03-31-2011, 08:46 PM
jdm113497
Convert year to roman numeral.
I need help with a program that inputs a year and outputs it in roman numerals. It needs to use the "if" statement. I'm really not even sure where to start.

Thanks if anyone can help.
• 03-31-2011, 09:06 PM
Iron Lion
When I wrote a program to do the same thing it ended up being a rather large and inelegant series of if-else statements. If I was going to rewrite it now, I'd probably write a separate method to which I'd pass each of the last three digits of the year, like so...

Code:

```private String parseDigit(int num, char fiveChar, char oneChar) {   /*     * Since the algorithm to produce Roman numerals for each of the last     * three digits is the same, with only the two characters used changed,     * the code you write here can be used for each of those digits     */ } public String intToRoman(int year) {     String output;     // ...rest of code...     output += parseDigit(year%10, 'V', 'I'); //Gets the Roman numerals for the last digit     return output; }```
Hope that's helped without giving too much away.
• 03-31-2011, 10:15 PM
Zack
If you're struggling with the conceptual stage, take a set of numbers (perhaps 5, 8, 11, 14, 16, 49, 51, 99, 133) and do them on paper. Keep note of the steps you have to take for each one, and you can begin to theorize what you might have to do in terms of code.