package de.codegym.task.task02.task0216;
/*
Die kleinste aus drei Zahlen
*/
public class Solution {
public static int min(int a, int b, int c) {
int m = 0;
if ((a < b)
&& (a < c))
m = a;
else if ((b < a)
&& (b < c))
m = b;
else
m = c;
return m;
}
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));
}
}
Was ist falsch? Die Methode gibt doch die kleinste Zahl aus?
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
6 May 2021, 17:54
I tried this code with the numbers 3, 3, 5 and it output 5. It should have output 3. There seems to be a bug in the algorithm that does not arrive at the correct answer for all combinations of 3 numbers.
0
Gera
7 May 2021, 07:10
Thanks. You're right.
0