Results 1 to 3 of 3
  1. #1
    Felissa is offline Member
    Join Date
    Jun 2007
    Posts
    95
    Rep Power
    0

    Default Convert roman numerals to integers

    Hello, The project is converting roman numerals to integers and integers to roman numerals.
    I can get it to work if I ask the user to choose from an option menu..what I would like to do is just have the code read through and check to see if a string or an integer was entered in the input line....I tried both the while loop and the if statement...

    Java Code:
    public static int value(char letter) // used for switch case for conversion
    
    
    given = input.readline();
    ei: if(given == value) and if (given == num) do this....I keep getting values
    cannot be resolved.
    Thanks.

    Felissa:p

  2. #2
    Marcus is offline Member
    Join Date
    Jun 2007
    Posts
    92
    Rep Power
    0

    Default

    You can check if a String is an int by doing something like:
    Java Code:
     String myString = "12345";
     int value;
     
     try
     {
         value = Integer.parseInt( myString );
     }
     catch( NumberFormatException nfe )
     {
         System.out.println( "please enter a valid number" );
     }
    Of course, your logic might be different but if the system can't parse the string into an Integer it will throw the NumberFormatException.

    Greetins.

    Marcus:cool:

  3. #3
    Felissa is offline Member
    Join Date
    Jun 2007
    Posts
    95
    Rep Power
    0

    Default

    Thanks for your help, that error is gone for now. I have two more errors.

    Java Code:
    expected "{", ;
    this error is coming from this line

    Java Code:
    private int charToNumber(char letter) //which leads to switch (letter)
    And misplaced construct and expected "{", ;

    Java Code:
    public int toInt()
    {
    return num;}
    I found a website that explains errors, but what it suggested didn't work.


    thanks for helping me!

    Felissa:p

Similar Threads

  1. Reading Integers from a text file
    By tress in forum New To Java
    Replies: 6
    Last Post: 02-26-2011, 05:45 PM
  2. Finding Median of X Integers
    By Hasan in forum New To Java
    Replies: 3
    Last Post: 08-12-2008, 02:06 PM
  3. Replies: 4
    Last Post: 04-16-2008, 01:26 PM
  4. Replies: 2
    Last Post: 04-16-2008, 12:35 PM
  5. Random Integers
    By www.kwalski.com in forum Java Applets
    Replies: 8
    Last Post: 12-09-2007, 05:49 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
  •