Error with return in Java? -



Error with return in Java? -

i error in code part of code:

public boolean findcustomer(string inpersonalnumber){ // check if personal number exist (int i=0; i<customerlist.size();i++) { if(customerlist.get(i).getcustomerpersonalnumber().equals(inpersonalnumber)){ homecoming true; } } homecoming true; }

when remove first homecoming true , instead lastly homecoming true, don't error in eclipse code, why can't have first place , same? thanks!

edit: error message eclipse say: method must homecoming result of type boolean. i'm confused because isn't have done?!

yes, break must in code

can write method in other way?

edit number 2 why isn't code working?

public boolean findcustomer(string inpersonalnumber){ // check if personal number exist (int i=0; i<customerlist.size();i++) { if(customerlist.get(i).getcustomerpersonalnumber().equals(inpersonalnumber)){ homecoming true; } else { homecoming false; } } }

this method returns boolean value don't understand why error!? code looks right me?

your edit #2 doesn't compile because there possibility code won't come in for-loop. case if customerlist.size() 0. prepare this, you'll need add together homecoming statement after for-loop well:

// check if personal number exist (int i=0; i<customerlist.size();i++) { if(customerlist.get(i).getcustomerpersonalnumber().equals(inpersonalnumber)){ homecoming true; } else { homecoming false; } } homecoming false;

another point here code doesn't logically create much sense: only homecoming true or false based on first item in list. , not want. take closer @ several of other reply here, many of examples how can this.

java

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -