Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-02-2007, 12:16 AM
Member
 
Join Date: Jun 2007
Posts: 95
Rep Power: 0
Felissa is on a distinguished road
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...

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
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 07-02-2007, 12:21 AM
Member
 
Join Date: Jun 2007
Posts: 92
Rep Power: 0
Marcus is on a distinguished road
Default
You can check if a String is an int by doing something like:
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-02-2007, 12:27 AM
Member
 
Join Date: Jun 2007
Posts: 95
Rep Power: 0
Felissa is on a distinguished road
Default
Thanks for your help, that error is gone for now. I have two more errors.

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

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

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
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding Median of X Integers Hasan New To Java 3 08-12-2008 03:06 PM
[SOLVED] Integers (averages and remainders)...need help Zebra New To Java 4 04-16-2008 02:26 PM
return Set .toArray(); method as an array of integers maxim New To Java 2 04-16-2008 01:35 PM
Reading Integers from a text file tress New To Java 3 04-03-2008 04:48 AM
Random Integers www.kwalski.com Java Applets 8 12-09-2007 06:49 PM


All times are GMT +2. The time now is 03:12 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org