Created
April 20, 2013 14:14
-
-
Save enile8/5426118 to your computer and use it in GitHub Desktop.
A simple little recursion method example.
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
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