Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 3rd, 2007, 08:34 PM
ff4930 ff4930 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 17 ff4930 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 7 m 59 sec
Reputation Power: 0
Stuck with "need return statement" error, but my returns are fine

Hello peeps, thanks for viewing and taking the time out to help me.

Code:
public static int compareTime(String time1, String time2){
 
  String firstLine = time1;
  StringTokenizer firstNumTime = new StringTokenizer(firstLine, ":");
  int realNumTime1 = Integer.parseInt(firstNumTime.nextToken());  
  
  String secondLine = time2;
  StringTokenizer secondNumTime = new StringTokenizer(secondLine, ":");
  int realNumTime2 = Integer.parseInt(secondNumTime.nextToken());  
  
 
  if( (realNumTime1 - realNumTime2) < 0)
    return -1;

  if( (realNumTime1 - realNumTime2) > 0)
    return 1;
  
 }// compareTime



this method is suppose to read in 2 strings
"12:57" and "2:45"

the method then takes in the first number before the ":" and converts it into an integer.

The return statements are clearly stated, but when compiled I get
"missing return statement"
}//compareTime
1 error

Reply With Quote
  #2  
Old March 22nd, 2007, 04:06 AM
daniel_g daniel_g is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 60 daniel_g User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 3 m 50 sec
Reputation Power: 3
When you use if/else statements, you always need a just in case return.
Code:
  if( (realNumTime1 - realNumTime2) < 0)
    return -1;

  if( (realNumTime1 - realNumTime2) > 0)
    return 1;
return 0; //return whatever, say realNumTime1 - realNumTime2=0 then you would be stuck without this.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Stuck with "need return statement" error, but my returns are fine


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT