Results 1 to 3 of 3
- 07-01-2007, 11:16 PM #1
Member
- Join Date
- Jun 2007
- Posts
- 95
- Rep Power
- 0
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...
cannot be resolved.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
Thanks.
Felissa:p
- 07-01-2007, 11:21 PM #2
Member
- Join Date
- Jun 2007
- Posts
- 92
- Rep Power
- 0
You can check if a String is an int by doing something like:
Of course, your logic might be different but if the system can't parse the string into an Integer it will throw the NumberFormatException.Java Code:String myString = "12345"; int value; try { value = Integer.parseInt( myString ); } catch( NumberFormatException nfe ) { System.out.println( "please enter a valid number" ); }
Greetins.
Marcus:cool:
- 07-01-2007, 11:27 PM #3
Member
- Join Date
- Jun 2007
- Posts
- 95
- Rep Power
- 0
Thanks for your help, that error is gone for now. I have two more errors.
this error is coming from this lineJava Code:expected "{", ;
And misplaced construct and expected "{", ;Java Code:private int charToNumber(char letter) //which leads to switch (letter)
I found a website that explains errors, but what it suggested didn't work.Java Code:public int toInt() { return num;}
thanks for helping me!
Felissa:p
Similar Threads
-
Reading Integers from a text file
By tress in forum New To JavaReplies: 6Last Post: 02-26-2011, 05:45 PM -
Finding Median of X Integers
By Hasan in forum New To JavaReplies: 3Last Post: 08-12-2008, 02:06 PM -
[SOLVED] Integers (averages and remainders)...need help
By Zebra in forum New To JavaReplies: 4Last Post: 04-16-2008, 01:26 PM -
return Set .toArray(); method as an array of integers
By maxim in forum New To JavaReplies: 2Last Post: 04-16-2008, 12:35 PM -
Random Integers
By www.kwalski.com in forum Java AppletsReplies: 8Last Post: 12-09-2007, 05:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks