I am a new to coding in Java and I am struggling trying to understand why things don't work. I have a class called Geek.java and under it I have a whole bunch of methods. One of the methods I was asked to do for my class was to find the smallest integer of 3 integers.
public int smallest(int num1, int num2, int num3){
if (num1 < num2){
if (num1 < num3 ){
return num1;
}
}
if (num2 < num1){
if (num2 < num3){
return num2;
}
}
if (num3 < num1){
if (num3 < num2){
return num3;
}
}
else
return num1;
}
Ignoring logical errors, as I understand, there must be a default return value if none of the if conditions match which should be specified by the else. However, eclipse is still telling me it "must return a value of type int." I apologize if the answer to this has already been stated before, but I can't seem to find it. Thank you,
Aucun commentaire:
Enregistrer un commentaire