This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

converting decimal number to roman number  RSS feed

 
hem kumar
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all...is there any way by which i can convert a decimal number to a roman number in java.....please suggest....thanks...
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like many programs, the first step is to carefully describe the process in English before trying to code it in Java. If you're not clear on the steps that are required, there's little chance of the code working.

In this case, I suggest you start small and gradually expand your program. For example, write a program that covers cases 1-10 first. When that works, expand it to cover 1-20. When that works, expand it to cover 1-50. Etc. This should help you see the patterns for extending it to cover all cases.
 
hem kumar
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually i was looking forward to the code to develope the programme. I am not getting the logic. So any help will be appreciated...Thanks in advance....
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See Wikipedia - Roman Numerals.

I'm certainly no expert on the details, so I would take my guidance from the statement, "In cases where it may be shorter, it is sometimes allowable to place a smaller, subtractive, symbol before a larger value, so that, for example, one may write IV or iv for four, rather than iiii."
 
Skippy Henderson
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you would first of all want to figure out the major building blocks I = 1, V = 5, X = 10, etc.,

Then you would want to figure out how to replace these numbers with their corresponding letters.

I would have thought that your best bet would be to try doing something with numbers that can be divided by the larger objects.

I wouldnt neccesarily agree that working 1-10 first would be the best bet because they may need to be written as special exceptions. 1-3 at least. After that you could probably work something out based on numbers that divide by 5 and divide by 10 and then 50 and then 100 etc. At least thats how I would do it.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Skippy Henderson:
...I wouldnt neccesarily agree that working 1-10 first would be the best bet because they may need to be written as special exceptions. 1-3 at least...

I thought writing the 1-10 code was a good start, because this ends up being used in all cases (handling the remainder after dividing out the larger "chunks"). Also, the basic logic of the special cases in 1-10 apply to the expanded cases as well.

(Actually, I didn't write 1-3 as special cases. My special cases were 4 and 9.)
 
Amit Singla
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i know i am very late in the reply but i came across this problen just now.
below is the programme to do the task. copy it and run it
-----------------------------------------------------------------
package com.test;

import java.util.regex.Pattern;

public class Roman2Decimal
{
DELETED. CR
}
[ June 20, 2008: Message edited by: Campbell Ritchie ]
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sing Laaaa:
i know i am very late in the reply but i came across this problen just now.
below is the programme to do the task. copy it and run it

PLEASE don't do this. Handing out the answer doesn't help anyone... in fact, quite the opposite. If this is a homework assignment and someone uses it, they are cheating and in some cases could be kicked out of the university.

at a minimum, it robs the person the chance to learn how to do think throught the problem for themselves.
 
Campbell Ritchie
Marshal
Posts: 55751
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by fred rosenberger:

PLEASE don't do this.
Agree. And please don't resurrect such old threads.


Fred, sorry, but I had decided to delete the quoted code before I saw your reply.
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Sing Laaaa",

Your name violates our naming policy. Please change it accordingly.

Thank you,

Rob
 
Amit Singla
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry for the same. Actually i was posting for the first time and was not aware of few things.

I will take care from next time.
 
Campbell Ritchie
Marshal
Posts: 55751
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!