The first question refers to my solution which appears at the very bottom, the second refers to the screenshot I've attached.
1. Can't I declare and initialize variables in the body of the if-clause and for the case I can't, why is this?
2. In the screenshot I see my alternative approach. There I was declaring the variable before the if clauses, in the body of the method itself, and then I am initializing the variables in the bodies of the if-clauses. There, the compiler said that the variable might not get initialized. But in my understanding, one of the cases regarding the if clauses will be picked necessarily, so that the variable gets initialized anyhow. Am I wrong about this?
![]()

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 kleinsteZahl;
if(a <= b && a <= c)
int kleinsteZahl = a;
else if (b <= a && b <= c)
int kleinsteZahl = b;
else if (c <= a && c <= b)
int kleinsteZahl = c;
return kleinsteZahl;
// int m1 = a < b ? a : b;
// int m2 = m1 < c ? m1 : 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));
}
}