Results 1 to 6 of 6
  1. #1
    tylerkung is offline Member
    Join Date
    Sep 2011
    Posts
    5
    Rep Power
    0

    Default String to Int: Roman Numeral Class

    I'm making a roman numeral program where I enter any roman numeral (i.e XI) and receive an output of 11. I'm having trouble setting letters to integers

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: String to Int: Roman Numeral Class

    having trouble setting letters to integers
    Can you give an example?
    By letters do you mean Strings? See the Integer class. It has a method to convert a String to an integer.

  3. #3
    tylerkung is offline Member
    Join Date
    Sep 2011
    Posts
    5
    Rep Power
    0

    Default Re: String to Int: Roman Numeral Class

    Uhhh well I was going to have the user input a value through Scanner and set it as

    String word = reader.nextLine();

    and then set X to be 10, I to be 1, etc, and then calculate a value. I'm a bit confused as to which function does that.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: String to Int: Roman Numeral Class

    I'm a bit confused as to which function does that.
    Java does not have a method for Roman Numerals. You will have to write one.

    I don't know what classes you are allowed to use with this assignment. The Map class would be useful.
    Or you might have to use a chain of if/else if statements to get the numeric value for a letter.
    Last edited by Norm; 09-22-2011 at 01:58 AM.

  5. #5
    tylerkung is offline Member
    Join Date
    Sep 2011
    Posts
    5
    Rep Power
    0

    Default Re: String to Int: Roman Numeral Class

    Quote Originally Posted by Norm View Post
    It has a method to convert a String to an integer.
    Yeah, that's what I'm trying to write. Which method does this? ^^

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: String to Int: Roman Numeral Class

    Quote Originally Posted by tylerkung View Post
    Yeah, that's what I'm trying to write. Which method does this? ^^
    Integer.parseInt(...) does this nicely. Have a look at the Integer API for the details.

Similar Threads

  1. Convert year to roman numeral.
    By jdm113497 in forum New To Java
    Replies: 2
    Last Post: 03-31-2011, 09:15 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. Replies: 11
    Last Post: 11-02-2010, 05:46 PM
  5. Roman numeral to Decimal
    By hector100 in forum Advanced Java
    Replies: 3
    Last Post: 04-04-2009, 07:48 PM

Posting Permissions

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