Post

Recursion_팩토리얼

✅ 재귀함수를 이용해 팩토리얼을 계산하는 함수를 만드세요

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Main {
    public int DFS(int n){
        if(n==1) return 1;
        else{
            return DFS(n-1)*n;
        }
    }
    public static void main(String[] args) {
        Main T = new Main();
        Scanner sc= new Scanner(System.in);
        int n= sc.nextInt();
        System.out.println(T.DFS(n));
    }
}

🔵 ThingsILearned

코딩공책-56

This post is licensed under CC BY 4.0 by the author.