Ich habe folgenden Code:
[CODE lang="java" title="Rekursion 11.11"]public class Rekursion {
public static void main(String[] args) {
System.out.println(power(100));
}
static int power(int x)
{
if (x > 0)
return (2*power(x-1)+1);
else
return (1);
}
}[/CODE]
Als Konsolen Output kommt -1 raus... Warum ? Und wie löse ich die Aufgabe ? Brauche ich 2 Rekursionen ?
[CODE lang="java" title="Rekursion 11.11"]public class Rekursion {
public static void main(String[] args) {
System.out.println(power(100));
}
static int power(int x)
{
if (x > 0)
return (2*power(x-1)+1);
else
return (1);
}
}[/CODE]
Als Konsolen Output kommt -1 raus... Warum ? Und wie löse ich die Aufgabe ? Brauche ich 2 Rekursionen ?