Ich habe folgendes Programm:
public class test {
public static void main(String[] args) {
System.out.println(fakulteat(5));
}
public static int fakulteat(int zahl) {
if (zahl == 1) {
return 1;
} else {
return zahl * fakulteat(zahl - 1);
}
}
}
Hier wird jetzt ja die Fakultät berechnet durch diese rekursive Methode.
Mein Problem steckt folgender Zeile:
return zahl * fakulteat(zahl - 1);
Damit gibt man dann so gesagt " 5 * 4! " an die Methode zurück.
Was ich mich aber Frage ist halt, wieso " fakulteat(zahl - 1) " jetzt eine Fakultät darstellt. Der Methode gibt sich selbst damit doch nur einen Wert zurück, woher weiß aber die Methode, dass dann z.B. 4! = 1 * 2 * 3 * 4 gemeint ist?