0

So as of recent I am testing out using methods that return a value, and I keep getting an error stating that I am missing a return statement in my method "basicPoints". I have a return statement, but I'm not sure why it keeps giving me this error, do I need to place the return statement in a different portion of the method?

public class Bridge {
private static int answer;

public static void main(String[] args) {
    basicPoints(2, "clubs");

    System.out.println("Points equal: " + ans);
}

public static int basicPoints(int level, String suit){

    if (suit.equalsIgnoreCase("clubs")){

        int ans;
        ans = level * 20;
        return ans;

    }    

}

}

1 Answers1

0

Your issue is that when the method runs and let's say suit is "hearts", then the method won't return anything because it never crosses a return statement. Try placing a return statement after your if statement. For example, return -1 if you didn't find that suit and didn't test for it

Jaboyc
  • 567
  • 1
  • 8
  • 16