Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

missing return statement...

Posted on 2011-10-10
4
Medium Priority
?
216 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:Mike Eghtebas
  • 2
  • 2
4 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36945904
because if it is not true
there is no returtn statement - you should add
else return false;
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 36945909
           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?
0
 
LVL 47

Accepted Solution

by:
for_yan earned 1000 total points
ID: 36945953
Well you can do like that

if("0123456789ABCDEF".indexOf(str) > -1)return true;
else return false;

but  you need to be sure that you string str would not be of two chars

you can say:

if("0123456789ABCDEF".indexOf(str) > -1  && str.length() == 1)return true;
else return false;


0
 
LVL 34

Author Closing Comment

by:Mike Eghtebas
ID: 36946110
Thank you.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month21 days, 1 hour left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question