public class Solution {
public static int min(int a, int b, int c, int d) {
int min2;
int e = min(a, b);
if (e < c && e < b)
min2 = e;
else if (c < e && c < d)
min2 = c;
else
min2 = d;
return min2;
}
public static int min(int a, int b) {
int min;
if (a < b)
min = a;
else
min = b;
return min;

# can someone tell me whats wrong with this one ??

Resolved

Comments (4)

- Popular
- New
- Old

You must be signed in to leave a comment

Guadalupe Gagnon

30 March 2021, 17:36

It doesn't return the correct answer. I tried it with the numbers:
2, 2, 5, 3457
And it output that the minimum was 3457.

+1

Aryan Babaie

2 April 2021, 17:58

Thanks, but I know it doesn't. can you tell me what's wrong with it?

0

Guadalupe Gagnon

2 April 2021, 19:03solution

It is the logic say that for the code:
a = 2
b = 2
c = 5
d = 3457
The logic would work like this:

The min(int, int) method works fine. In the min(int, int, int, int) method you can use the min(int, int) method more than once. In your code you use it to figure out the min of 'a' and 'b'. You could then use it to figure out the min of 'c' and 'd'. Then you can use it a third time to figure out the min of those two numbers.
+2

Aryan Babaie

3 April 2021, 17:04

Thank you for taking your time on this and it helped a lot🤘

0