+ 3
Can someone tell me what I did wrong?
Look at my code, I'm practicing overriding. https://code.sololearn.com/c22E1nV3ZTVU/?ref=app
3 Answers
+ 6
This method doesn't have a return statement for every possible route the code might take:
static int min(int a, int b, int c, int d) {
if(a > d) {
return c;
} else if ( d > c) {
return b;
} else if ( b > a) {
return a;
} else if(c > b) {
return d;
}
}
Because all the statements are if or else-if statements it is possible that none of them run and there isn't a return statement for that condition. Add a return statement to the end after the last else-if or change the last one to simply an else statement.
You also have some logic problems if you're trying to actually return the minimum value from each of the methods in their current state.
+ 17
solution for the logical error (for minimum number)
if (a < b) {
if (a < c) return a;
else return c;
}
else {
if (b < c) return b;
else return c;
}
//thats for 3 variables , similarily U can form for 4 variables š
+ 3
Thank you @ChaoticDawg, I forgot about that. Have a good day and everyone else who helps me