Skip to content

Instantly share code, notes, and snippets.

@enile8
Created April 20, 2013 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enile8/5426118 to your computer and use it in GitHub Desktop.
Save enile8/5426118 to your computer and use it in GitHub Desktop.
A simple little recursion method example.
public class RecursionExample {
public static void main(String[] args) {
// call the method
int fact = myFactorial(3);
// print the result
System.out.println(fact);
}
public static int myFactorial(int integer) {
if (integer == 1) // base case
return 1;
else
return (integer * (myFactorial(integer - 1)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment