This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programming Diversions and the fly likes [Easy/Tough] Roman Numerals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "[Easy/Tough] Roman Numerals" Watch "[Easy/Tough] Roman Numerals" New topic
Author

[Easy/Tough] Roman Numerals

Jignesh Malavia
Author
Ranch Hand

Joined: May 18, 2001
Posts: 81
Write a program that converts Roman numerals to Arabic and reverse.
Values:
I = 1 (one)
V = 5 (five)
X = 10 (ten)
L = 50 (fifty)
C = 100 (one hundred)
D = 500 (five hundred)
M = 1000 (one thousand)
Examples:
30 is written as XXX but 15 is not written as VVV
40 is written as XL but 45 is not written as VL
9 is written as IX but 49 is not written as IL and 99 is not written as IC
243 is written as CCXLIII
1510 is written as MDX
1999 is written as MCMXCIX
4,9,40,90,400,900 == IV,IX,XL,XC,CC,CM respectively
Rules:
1) No googling for any more rules or hints.
PS:
If the above is just plain boring, then you can solve this quiz or read about the 1999 problem
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Here's my lash at it.
Joe Pluta
Ranch Hand

Joined: Jun 23, 2003
Posts: 1376
Here's my shot at it:

This will throw an exception if the Roman numeral is incorrect; it doesn't do any nice error checking like Michael's, but it's short and simple.
Joe
Jignesh Malavia
Author
Ranch Hand

Joined: May 18, 2001
Posts: 81
Yup!
You both get an A+ :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Easy/Tough] Roman Numerals