The Artima Developer Community
Sponsored Link

Java Answers Forum
writing methods

1 reply on 1 page. Most recent reply: Nov 8, 2005 9:25 PM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Karie Monato

Posts: 1
Nickname: popeye
Registered: Nov, 2005

writing methods Posted: Nov 8, 2005 3:46 PM
Reply to this message Reply
Advertisement
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;

}

}
The compiler is giving me this errror: "return statement missing". How do I make this work? Thanks in advance.


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: writing methods Posted: Nov 8, 2005 9:25 PM
Reply to this message Reply
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.

Flat View: This topic has 1 reply on 1 page
Topic: Horizontal & Vertical Lines Previous Topic   Next Topic Topic: Comparing Arrays

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use