Results 1 to 3 of 3
Thread: Convert year to roman numeral.
- 03-31-2011, 07:46 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 7
- Rep Power
- 0
- 03-31-2011, 08:06 PM #2
Senior Member
- Join Date
- Nov 2010
- Posts
- 210
- Rep Power
- 3
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...
Hope that's helped without giving too much away.Java 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; }
- 03-31-2011, 09:15 PM #3
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.
Similar Threads
-
Convert the number to Roman numerals
By ŖàΫ ỏƒ Ңόρę in forum New To JavaReplies: 9Last Post: 11-29-2012, 10:44 PM -
convert roman numeral to number
By the beginner in forum New To JavaReplies: 3Last Post: 01-27-2011, 06:49 AM -
How to identify a roman numeral
By dunworry in forum New To JavaReplies: 13Last Post: 12-19-2010, 08:13 AM -
Convert roman numerals
By matzahboy in forum New To JavaReplies: 4Last Post: 02-21-2010, 10:06 PM -
Roman numeral to Decimal
By hector100 in forum Advanced JavaReplies: 3Last Post: 04-04-2009, 07:48 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks