public class Solution {
public static int min(int a, int b, int c, int d) {
//write your code here
int m2 = min(min(int a, int b), min(int c, int d));
return m2;
}
public static int min(int a, int b) {
//write your code here
int m1 = a < b ? a : b;
return m1;
}
public static void main(String[] args) throws Exception {
System.out.println(min(-20, -10));
System.out.println(min(-20, -10, -30, -40));
System.out.println(min(-20, -10, -30, 40));
System.out.println(min(-40, -10, -30, 40));
}
Why does it not work?
Under discussion
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Misiu
21 November 2020, 11:52
int m2 = min(min(int a, int b), min(int c, int d)); not correct
Variables a, b, c, d already are declared in signature of the method: min(int a, int b, int c, int d).
0
Rishabh Joshi
22 November 2020, 09:02
but (int c) and (int d) are just arguments for min(int a, int b)
0
Misiu
22 November 2020, 11:23
There should be one declaration of variables in method.
Line 1 - declaaration: a, b, c, d are integers
Line 3 - use a, b, c, d (without int prefix). We (and computer) know they are integers. 0
Rishabh Joshi
23 November 2020, 08:40
okayyyy, got it and it worked as well. I am glad atleast the logic was correct. Thanks for your help :D
0