-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_10872.java
More file actions
36 lines (35 loc) · 794 Bytes
/
_10872.java
File metadata and controls
36 lines (35 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package backjoon;
// https://www.acmicpc.net/problem/10872
// 팩토리얼
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class _10872 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
// sol1 반복문 사용
// memory 11452 runtime 76
/*
int fac = 1;
for(int i=1; i<=N; i++){
fac *= i;
}
System.out.println(fac);
*/
// sol2 재귀사용
// memory 11480 runtime 76
int sum = factorial(N);
System.out.println(sum);
}
public static int factorial(int n){
if(n <= 1) return 1;
return n * factorial(n-1);
}
}
/*
input
10
output
3628800
*/