package zh.codegym.task.task02.task0217;
/*
四个数字中的最小值
*/
public class Solution {
public static int min2(int a, int b, int c, int d) {
int m;
int z = min1(c, d);
if ( a < b ){
if (a < z){
m = a;
}
else{
m = z;
}
}
else{
if (b < z){
m = b;
}
else{
m = z;
}
}
return m;
}
public static int min1(int a, int b) {
int s;
if (a < b)
s = a;
else
s = b;
return s;
}
public static void main(String[] args) throws Exception {
int a = -20, b = -10;
int m1 = min1(a, b);
System.out.println(m1);
int c = -20, d = -10, e = -40, f = -40;
int m2 = min2( c, d, e, f);
System.out.println(m2);
int g = -20, h = -10, i = -30, j = 40;
int m3 = min2(g, h, i, j);
System.out.println(m3);
int k = -40, n = -10, o = -30, p = 40;
int m4 = min2( k, n, o, p);
System.out.println(m4);
//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));
}
}
package zh.codegym.task.task02.task0217;
/*
四个数字中的最小值
*/
public class Solution {
public static int min2(int a, int b, int c, int d) {
int m;
int z = min1(c, d);
if ( a < b ){
if (a < z){
m = a;
}
else{
m = z;
}
}
else{
if (b < z){
m = b;
}
else{
m = z;
}
}
return m;
}
public static int min1(int a, int b) {
int s;
if (a < b)
s = a;
else
s = b;
return s;
}
public static void main(String[] args) throws Exception {
int a = -20, b = -10;
int m1 = min1(a, b);
System.out.println(m1);
int c = -20, d = -10, e = -40, f = -40;
int m2 = min2( c, d, e, f);
System.out.println(m2);
int g = -20, h = -10, i = -30, j = 40;
int m3 = min2(g, h, i, j);
System.out.println(m3);
int k = -40, n = -10, o = -30, p = 40;
int m4 = min2( k, n, o, p);
System.out.println(m4);
//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));
}
}