User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 456,592 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,529 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 18334 | Replies: 4
Reply
Join Date: Aug 2004
Posts: 11
Reputation: i_me_roo is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
i_me_roo i_me_roo is offline Offline
Newbie Poster

missing return statement

  #1  
Aug 18th, 2004
Hi guys,

Im trying to compile this class below, but its just not working, it keeps sating 'missing return statement' int the method declaration line. Can u see to check if there is anything missing in my code or if iv done something wrong??

Thanks!


public class swapping {

public int trade(int []a, int b){ //says theres a missing return statement
int temp=0;
for (int n = 1; n < b; n++) {
for (int m = 0; m < b - 1; m++) {
if (a[m] > a[m] + 1) {
temp = a[m];
a[m] = a[m+1];
a[m+1] = temp;
return a[m];
}
}
}
}
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2004
Posts: 604
Reputation: freesoft_2000 is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 6
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: missing return statement

  #2  
Aug 18th, 2004
hello everyone,
Your class main is missing and you added an extra bracket at the end

Yours Sincerely

Richard West
Reply With Quote  
Join Date: Aug 2004
Location: Hanover
Posts: 152
Reputation: cosi is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 1
cosi's Avatar
cosi cosi is offline Offline
Junior Poster

Re: missing return statement

  #3  
Aug 18th, 2004
Well I'm sure that i_me_roo probably has a main and extra bracket at the end. The compiler complaint was about return statements.

i_me_roo if you look at the code, you'll see that it is possible to go straight through the function without hitting the return statement. This is what the compiler is complaining about. The function returns an int, so all paths of execution must have a return value;

My suggestion is to have a 'return ERROR', or 'return 0', or 'return -1' after the for loops if you never intend to reach that line of execution. This is the best advice I can think of since I have no idea about the context of the function you wrote.


Ed
Reply With Quote  
Join Date: Jul 2004
Location: Pakistan
Posts: 1,673
Reputation: nanosani is an unknown quantity at this point 
Rep Power: 8
Solved Threads: 50
Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: missing return statement

  #4  
Aug 19th, 2004
public class swapping {

  public int trade(int []a, int b){ //says theres a missing return statement 
    int temp=0;
    for (int n = 1; n < b; n++) {
      for (int m = 0; m < b - 1; m++) {
        if (a[m] > a[m] + 1) { 
          temp = a[m];
          a[m] = a[m+1];
          a[m+1] = temp;
          return a[m]; 
        }
      }
    }
    return 0;
  }
}

Now it'll run well.
Reply With Quote  
Join Date: Aug 2004
Posts: 11
Reputation: i_me_roo is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
i_me_roo i_me_roo is offline Offline
Newbie Poster

Re: missing return statement

  #5  
Aug 22nd, 2004
Thank you very much for ur help all of u, it is working now!! Thanks!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 6:43 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC