Created
February 24, 2015 18:22
-
-
Save heckenmann/50ab2038e5f751343468 to your computer and use it in GitHub Desktop.
Rekursion
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 Rekursion { | |
public static void main(String[] args) { | |
int start = -5; // Von diesem Wert an wird gezählt | |
int ende = 5; // Bis zu diesem Wert wird gezählt; Muss größer gleich "start" sein! | |
count(start, ende); | |
} | |
// Rekursive Definition der Methode count(..) | |
public static void count(int momentanerWert, int ende){ | |
System.out.println(momentanerWert); // Momentaner Wert wird ausgegeben | |
// Falls, der momentane Wert kleiner als "ende" ist, | |
// wird er erhöht und nochmal an count() übergeben. | |
if(momentanerWert < ende) { | |
count(momentanerWert + 1, ende); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment