• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

converting decimal number to roman number

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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."
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic