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 low = 0;
if (a <= b && a <= c && a <= d) {
low = a;
} else if (b <= a && b <= c && b <= d) {
low = b;
} else if (c <= a && c <= b && c <= d) {
low = c;
} else {
low = d;
}
return low;
}
public static int min(int a, int b) {
int lowest = 0;
if (a < b){
lowest = a;
} else {
lowest = b;
}
return lowest;
}
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));
}
}
and the answers comeback as:
-20
-40
-30
-40
and the one portion I did not pass is:
The min(a, b, c, d) method must use the min(a, b) method.
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 low = 0;
if (a <= b && a <= c && a <= d) {
low = a;
} else if (b <= a && b <= c && b <= d) {
low = b;
} else if (c <= a && c <= b && c <= d) {
low = c;
} else {
low = d;
}
return low;
}
public static int min(int a, int b) {
int lowest = 0;
if (a < b){
lowest = a;
} else {
lowest = b;
}
return lowest;
}
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));
}
}