Created
February 24, 2015 18:22
-
-
Save heckenmann/9b8c8537fb8a001efaa0 to your computer and use it in GitHub Desktop.
Rekursion (wechselseitig)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WechselRekursion { | |
public static void main(String[] args) { | |
methode1(0, 5); | |
} | |
// Diese Methode erhöht den Wert der Variablen "momentanerWert" um 2 | |
public static void methode1(int momentanerWert, int ende){ | |
System.out.println(momentanerWert); // Ausgabe des Wertes der Variablen "momentanerWert" | |
// Rekursionsanker | |
if(momentanerWert == ende){ | |
return; | |
} | |
methode2(momentanerWert + 2, ende); // Aufruf von "methode2()" | |
} | |
// Diese Methode verringert den Wert der Variablen "momentanerWert" um 1 | |
public static void methode2(int momentanerWert, int ende){ | |
System.out.println(momentanerWert); // Ausgabe des Wertes der Variablen "momentanerWert" | |
// Rekursionsanker | |
if(momentanerWert == ende){ | |
return; | |
} | |
methode1(momentanerWert - 1, ende); // Aufruf von "methode1()" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment