|
Re: writing methods
|
Posted: Nov 8, 2005 9:25 PM
|
|
Firstly please format your code properly... Secondly the last statement before exiting your method (with a curly brace) needs to be a return statement (unless you are using Java 5 upwards in which it can be embraced in a try catch or an if else just before the last curly brace of the method.
> The purpose of this method is to return a valid integer. >
public static int readInteger( String text, int start, int
end ) {
// Body of method readInteger
boolean num = true;
while ( !num ) {
System.out.print( text );
String s;
s = Stdin.readln();
if (isInteger(s)) {
int input = Integer.parseInt(s);
if ( start > end ) {
} else if ( input >= start && input <= end ) {
return input;
}
// Your return statement should actually be here...
// i.e. return whatever int you want....
// Just for compilations sake return 0 or 1 till you
// you figure out what actual value you want to return
return 0;
}
The compiler is giving me this errror: "return statement > missing". How do I make this work? Thanks in advance.
|
|