Convert roman numerals to decimal in java

Posted By: Achchuthan Yogarajah - 7:32 PM

Share

& Comment

Read a roman number and convert that into decimal. For such a problem we have to find a suitable solution. we need to write a method to read the Roman number and a converter. there is a  common patterns in Roman numbers and find a solution to convert.
For example , " III "means 1+1+1=3 , " V " means 5 " IV " means 4 how ?
let see , First read string and check from back to front .so now we have first " V " and " I " .now check last character is grater other one then " - " operator else " + "operator   ( if V > I then 5 - 1 = 4 )

Example :
" IX "       "1" "10" this mean 10 > 1 then 10 -1 =9.
" XIV "     "10""1""5" this mean 4 >1 so 5-1 = 4 and  renaming 10 ==>10+4 = 14

Output of this program :

run:
Enter roman number you want to convert
Command End to stop entering
i
I is equal to 1
iv
IV is equal to 4
ix
IX is equal to 9
xii
XII is equal to 12
xiv
XIV is equal to 14
c
C is equal to 100
xc
XC is equal to 90
m
M is equal to 1000
cm
CM is equal to 900
xm
XM is equal to 990
End
BUILD SUCCESSFUL (total time: 37 seconds)