Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Romain to arabic numbers converter

  1. #1
    Junior Member
    Join Date
    Oct 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Romain to arabic numbers converter

    Hi! so right now i'm trying to do a program to convert romain numbers to arabic numbers. My problem is that I don't have the right to use Methods and Arrays. Only loops and if/else. I actually have no clue on how to do it. N.B. I want clues, not all the code. #wouldbesomuchsimplewithaarrays


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Romain to arabic numbers converter

    Can you post some examples of the input and desired output?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Oct 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Romain to arabic numbers converter

    Exemple of the execution in the CMD:
    java romaintoarabic MCXI
    Converted number : 1111

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Romain to arabic numbers converter

    It's impossible to do what you've shown in Post #3 without using arrays. MCXI will be in args[0], and that's an array element. I'm also curious if you can use String's methods. Please be clearer about what you can/can't do or use and post what you've done so far.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Romain to arabic numbers converter

    Can you explain the logic for what to do with each Roman numeral character as it is read from the full number?
    For example what would you do with the 'C' from CM?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Oct 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Romain to arabic numbers converter

    Oh I'm sorry. I'm not counting it as a method. But you're right, I'm using the string method. As this point I can convert every single character to a numeral value and add them to each other. But here is my problem: Ex: java romaintoarabic IX Converted number : 11 But actually it should five me 9.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Romain to arabic numbers converter

    IX Converted number : 11 But actually it should five me 9.
    Given "IX" what does the code need to do when it sees the 'I'?

    Does the code need to reject invalid input: IXL or MCCM
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Romain to arabic numbers converter

    How are we supposed to help you without seeing your code and understanding all of the rules?

  9. #9
    Junior Member
    Join Date
    Oct 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Romain to arabic numbers converter

    I just actually don't know how to do it. Found out that my code is dope

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Romain to arabic numbers converter

    If you don't know the rules for constructing Roman numerals it will be very hard to write code to convert them. Do some research.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Dec 2013
    Posts
    13
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Romain to arabic numbers converter

    It is possible to convert Roman numbers to Arabic numbers by using loop and if-else statement. Here is my suggestion: read the Roman numbers from the left to the right. If the leftmost number is greater than the number next to it (to the right), then that number (the leftmost) is a positive number. If it is not, then it is a negative number. Then keep comparing the next number (to the right). Notice: in case both successive numbers are equal, treat them like a single number, and keep comparing.

    For example: XIV. We first compare X and I. Since X is greater than I, X is a positive number (+10). Then compare I and V. Since I is less than V, then I = -1. After V there is no number, then V = +5. So +10 - 1 + 5 = 14.

Similar Threads

  1. Converter
    By xdevilx3 in forum Java Theory & Questions
    Replies: 13
    Last Post: November 18th, 2013, 09:40 AM
  2. temperature converter
    By pranavk26 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: June 11th, 2013, 06:38 AM
  3. Arabic Issue with Struts 1.3
    By maqs.developer in forum Web Frameworks
    Replies: 0
    Last Post: July 24th, 2012, 03:52 AM
  4. RAndom string of Arabic text
    By saab613 in forum Java Theory & Questions
    Replies: 0
    Last Post: December 15th, 2011, 09:48 AM
  5. Piglatin Converter
    By jross21 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 14th, 2010, 12:09 PM

Tags for this Thread