Converting Decimal to Roman Numeral

In this post we will write a java program to convert a decimal number to equivalent Roman numeral.  Before we step in to the program, we will see what are the Roman symbols and its decimal values.


Roman Symbols and its values:
Roman SymbolDecimal value
I1
IV4
V5
IX9
X10
XL40
L50
XC90
C100
CD400
D500
CM900
M1000


Decimal Forming Rules:

1. When a symbol appears after a larger or equal symbol, then it is added
  • VI = V + I = 5 + 1 = 6
  • XXI = X + X + I = 10 + 10 + 1 = 21
2. But if the symbol appears before a larger symbol, the it is subtracted
  • IV = V - I = 5 - 1 = 4
  • IX = X - I = 10 - 1 = 9

Program :
With the below program, we can covert up to the maximum value 3000. If you want to covert more than 3000, just add more roman symbols in the thousands array.


Output:

Enter a decimal : 9
Roman is : IX

Enter a decimal : 30

Roman is : XXX

Enter a decimal : 2001

Roman is : MMI

No comments:

Post a Comment