Wednesday, 28 August 2013

Exiting a non void method? (Java)

Exiting a non void method? (Java)

I was wonder how you would go about exiting a method early. If this was a
void type, I would just do "return", however since this is an int type, it
wants me to return an integer. How do I return to main without returning
any integers. Thanks.
public static int binarysearch(String[] myArray, String target, int first,
int last)
{
int index;
if (first > last)
{
index = -1;
System.out.println("That is not in the array");
// Return to main here
}

No comments:

Post a Comment