Skip to content

Instantly share code, notes, and snippets.

@heckenmann
Created February 24, 2015 18:22
Show Gist options
  • Save heckenmann/50ab2038e5f751343468 to your computer and use it in GitHub Desktop.
Save heckenmann/50ab2038e5f751343468 to your computer and use it in GitHub Desktop.
Rekursion
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