Results 1 to 3 of 3
  1. #1
    jdm113497 is offline Member
    Join Date
    Mar 2011
    Posts
    7
    Rep Power
    0

    Default Convert year to roman numeral.

    I need help with a program that inputs a year and outputs it in roman numerals. It needs to use the "if" statement. I'm really not even sure where to start.

    Thanks if anyone can help.

  2. #2
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    4

    Default

    When I wrote a program to do the same thing it ended up being a rather large and inelegant series of if-else statements. If I was going to rewrite it now, I'd probably write a separate method to which I'd pass each of the last three digits of the year, like so...

    Java Code:
    private String parseDigit(int num, char fiveChar, char oneChar) {
       /*
        * Since the algorithm to produce Roman numerals for each of the last
        * three digits is the same, with only the two characters used changed,
        * the code you write here can be used for each of those digits
        */
    }
    public String intToRoman(int year) {
        String output;
        // ...rest of code...
        output += parseDigit(year%10, 'V', 'I'); //Gets the Roman numerals for the last digit
        return output;
    }
    Hope that's helped without giving too much away.

  3. #3
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    4

    Default

    If you're struggling with the conceptual stage, take a set of numbers (perhaps 5, 8, 11, 14, 16, 49, 51, 99, 133) and do them on paper. Keep note of the steps you have to take for each one, and you can begin to theorize what you might have to do in terms of code.

Similar Threads

  1. Convert the number to Roman numerals
    By ŖΫ ỏ Ңόρę in forum New To Java
    Replies: 9
    Last Post: 11-29-2012, 10:44 PM
  2. convert roman numeral to number
    By the beginner in forum New To Java
    Replies: 3
    Last Post: 01-27-2011, 06:49 AM
  3. How to identify a roman numeral
    By dunworry in forum New To Java
    Replies: 13
    Last Post: 12-19-2010, 08:13 AM
  4. Convert roman numerals
    By matzahboy in forum New To Java
    Replies: 4
    Last Post: 02-21-2010, 10:06 PM
  5. Roman numeral to Decimal
    By hector100 in forum Advanced Java
    Replies: 3
    Last Post: 04-04-2009, 07:48 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •