-
10872) 팩토리얼 - JAVA백준코딩일기 2020. 1. 15. 17:17
https://www.acmicpc.net/problem/10872
방법 1).
123456789101112131415public class Main {public static void main(String[] args) throws IOException{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));int N = Integer.parseInt(br.readLine());int result = 1;for(int index=1; index<=N; index++)result *= index;}} cs방법2) 재귀함수 이용
123456789101112131415161718public class Main {public static int factorial(int n) {if( n == 0)return 1;else{return n * factorial(n-1);}}public static void main(String[] args) throws Exception{BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));int n = Integer.parseInt(bf.readLine());System.out.println(factorial(n));}} cs'백준코딩일기' 카테고리의 다른 글
11726) 2×n 타일링 - Java (0) 2020.01.24 2004) 조합 0의 개수 - Java (0) 2020.01.15 1676) 팩토리얼 0의 개수 - JAVA (0) 2020.01.15 1158) 조세푸스 문제 - JAVA (0) 2020.01.06 2741) N 찍기 - JAVA (0) 2020.01.01