package pl.codegym.task.task02.task0216;
/*
Najmniejsza z trzech liczb
*/
public class Solution {
public static int min(int a, int b, int c) {
if (a <= b && a <= c){
int m2 = a;
}
else if (b <= a && b <= c){
int m2 = b;
}
else if (c <= a && c <= b){
int m2 = c;
}
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));
}
}
Ubigot
Poziom 6
What is wrong here?
Rozwiązane
Komentarze (2)
- Popularne
- Najnowsze
- Najstarsze
Musisz się zalogować, aby dodać komentarz
Mateusz
5 lutego 2022, 17:57
Skąd wzięło ci się int ? Powinno być return
0
Gellert Varga
9 maja 2021, 13:58
I got this error message while running the program:
/Solution.java:18: error: cannot find symbol
return m2;
This means that it try to use a variable called m2 that may not even be declared anywhere, so it is not recognized by Java.
More precisely: you only declared this variable in the "if" blocks.
Therefore, there may be a case that if none of the "if" conditions are met, so the variable m2 will not be declared, but still there will be this command that "return m2" - and in this case it is an undeclared variable = error.
Tip: declare m2 and give it an initial value (eg 0) in the method, but before all "if" blocks.
0