I figured out that I needed the <= but I don't understand why that was needed instead of just the < operand, when it was still returning the correct values.
My code was returning
1
-3
3
5
Code:
I'm sure I must be missing something but I for the life of me cannot figure out what it is. Thanks!
package com.codegym.task.task02.task0216;
/*
Minimum of three numbers
*/
public class Solution {
public static int min(int a, int b, int c) {
int m2;
if (c < b && c < a)
m2 = c;
else if (b < a && b < c)
m2 = b;
else
m2 = a;
return m2;
}
public static void main(String[] args) throws Exception {
System.out.println(min(1, 2, 3));
System.out.println(min(-1, -2, -3));
System.out.println(min(3, 5, 3));
System.out.println(min(5, 5, 10));
}
}
package com.codegym.task.task02.task0216;
/*
Minimum of three numbers
*/
public class Solution {
public static int min(int a, int b, int c) {
int m2;
if (c < b && c < a)
m2 = c;
else if (b < a && b < c)
m2 = b;
else
m2 = a;
return m2;
}
public static void main(String[] args) throws Exception {
System.out.println(min(1, 2, 3));
System.out.println(min(-1, -2, -3));
System.out.println(min(3, 5, 3));
System.out.println(min(5, 5, 10));
}
}