You can throw some custom exception like InvalidNumberException...
But in your method arg is 'int' type so I wonder how it won't be a valid number? Do you have a specific criteria defined for "valid number" in addition to it being an 'int'. e.g. if the number is between 10 and 100 then its valid, otherwise its considered invalid?
Joined: Oct 14, 2004
My main concern is
return true;//Value Matches else return false;//Value Doesn't Match If I called the method from another class I need to compare the returned value. I haven't seen any examples of this in my text But I did see it in a Assignment Solution !!!
It's pretty easy to get mislead by reading code fragments, but the code fragment you show doesn't look like anything that will compile or execute, without seeing the surrounding class. For one thing, most implementations of getChar() return the character value, not the integer value. Here is a brief but complete program that has been run (on Java 5 aka 1.5 aka Tiger) and works:
For more information see Recipe 10.5 of the Java Cookbook, 2nd Edition, page 262.
Ian [ October 14, 2004: Message edited by: Ian Darwin ]