For example, I want to create a function that can return any number (negative, zero, or positive).
However, based on certain exceptions, I\'d like the function to re
Absolutely! In your case, since the return values can be positive, 0, negative, or false, probably the best return value would be a JSONObject. In your code, you would add this import:
import org.json.JSONObject;
and in the function:
JSONObject retval = new JSONObject();
double x = b*b - 4*a*c;
if(x < 0){
retval.put("result", false);
}
else{
retval.put("result", x);
}
You potentially could also add another key:value pair to the retval to include the result type to help with checking it in the calling function.