package com.codegym.task.task02.task0217;
/*
Minimum of four numbers
*/
public class Solution {
public static int min(int a, int b, int c, int d) {
int m3=min(a,b);
int minValue;
int m1;
if(c<d){
c=m1;
}
else {
d=m1;
}
if(m1<m2){
m1=minValue;
}
else{
m2=minValue;
}
return minValue;
}
public static int min(int a, int b) {
int m2;
if(a<b){
a=m2;
}
else {
b=m2;
}
return m2;
}
public static void main(String[] args) throws Exception {
min(a,b,c,d)=min(min(a,b), min(c,d));
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));
}
}
hidden #10424566
Level 7
Kindly please help me understand this challenge i have tried many methods yet nothing works
Under discussion
Comments (8)
- Popular
- New
- Old
You must be signed in to leave a comment
hidden #10424566
5 February 2019, 01:09
Thank you Gaudalupe that really helped
+1
Guadalupe Gagnon
4 February 2019, 18:25
that line calls the min(a,b) method
these lines call the min(a,b,c,d) method
0
hidden #10424566
4 February 2019, 18:23
Thank you I have passed the challenge the error was calling min(min(a,b),min(c,d));in the main method. But still can't understand why my main method did not call the min (a, b) and (a, b, c, d) and still got verified. If you know kindly explain.
0
hidden #10424566
4 February 2019, 18:08
Do you mind explaining to me how you understand the question to this challenge, may that way I can get the problem to my code. I have corrected it as you've said, but still won't work. I keep getting the "cannot find symbol"
0
hidden #10424566
4 February 2019, 17:49
Thank you but i have tried that already yet my code would not work
0
Guadalupe Gagnon
4 February 2019, 17:48
In this code:
public static int min(int a, int b, int c, int d) {
int m3 = min(a,b);
int minValue;
int m1;
if(c<d){
c=m1;
}
else {
d=m1;
}
if(m1<m2){
m1=minValue;
}
else{
m2=minValue;
}
return minValue;
}
you need to swap the variables around because of the same reason pointed out below. Also there is no variable m2 declared in this, however the code is using one. I think you meant m3.
0
Guadalupe Gagnon
4 February 2019, 17:42
In this method:
The assignment operator (equals sign '=') assigns the variable on the left to the value on the right. This code should have m2 = (a or b), not the way that it is coded.
0
Guadalupe Gagnon
4 February 2019, 17:36
Next time just use the slide and don't copy and paste your code:
.
0