Last active
October 19, 2017 02:09
-
-
Save mizushou/43d65935e99be9bf2d860d873c5908d2 to your computer and use it in GitHub Desktop.
* nの階乗を計算する再帰関数
* 漸化式 : n! = n * (n-1)
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 Factorial { | |
//階乗を求める再帰関数 | |
static int factorial(int n) { | |
if(n==1) { | |
return 1; | |
} | |
return n * factorial(n-1); | |
} | |
public static void main(String[] args) { | |
int n = 5; | |
System.out.println(factorial(5)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment