The problem is the compiler only sees return statements within if statements. It thinks there's no guaranteed path through the method that has a return.
Something like this would work:
if(num1 <= num2 && num1 <= num3) {
return num1;
} else if(num2 <= num1 && num2 <= num1) {
return num2;
} else { //by matter of deduction
return num3;
}
Another possible solution:
public double getSmallest() {
double min = num1;
if(min > num2) {
min = num2;
}
if(min > num3) {
min = num3;
}
return min;
}
As a note, this particular solution is easily the most scalable. If instead of a handful of numbers, you had an array of numbers, you could assign min to the value of the first index, and then iterate through the entire collection comparing the value at each index to min, and if it's smaller, reassign min.
Above are probably the two best and most logical solutions. However, simply adding return 0 (or ANY return statement) after all the if statements will make the compiler happy. This will work... but it's sloppy in my opinion (at least in this case).