Link to home
Start Free TrialLog in
Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America

asked on

missing return statement...

A single upper case character is supplied to isHex() to return true it is hex 0 - F.

Q1: line public static boolean IsHex(String str) {  complains saying "missing return statement", why?

Q2: Is there a better way ofwriting this if statement?

Thank you.
public static boolean IsHex(String str) {
 
            if(str.equals("0") || str.equals("1") || str.equals("2") ||
               str.equals("3") || str.equals("4") || str.equals("5") ||
               str.equals("6") || str.equals("7") || str.equals("8") ||
               str.equals("9") || str.equals("A") || str.equals("B") ||
               str.equals("C") || str.equals("D") || str.equals("E") ||
               str.equals("F")) 
                return true;    
    }

Open in new window

Avatar of for_yan
for_yan
Flag of United States of America image

because if it is not true
there is no returtn statement - you should add
else return false;
Avatar of Mike Eghtebas

ASKER

           return(str.equals("0") || str.equals("1") || str.equals("2") ||
               str.equals("3") || str.equals("4") || str.equals("5") ||
               str.equals("6") || str.equals("7") || str.equals("8") ||
               str.equals("9") || str.equals("A") || str.equals("B") ||
               str.equals("C") || str.equals("D") || str.equals("E") ||
               str.equals("F"));

This seems to work. How about simplifying these cmparisions?
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you.