Skip to content

Instantly share code, notes, and snippets.

@mizushou
Last active October 19, 2017 02:09
Show Gist options
  • Save mizushou/43d65935e99be9bf2d860d873c5908d2 to your computer and use it in GitHub Desktop.
Save mizushou/43d65935e99be9bf2d860d873c5908d2 to your computer and use it in GitHub Desktop.
* nの階乗を計算する再帰関数 * 漸化式 : n! = n * (n-1)
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