재귀 | 카운트다운

카테고리 없음 2019. 8. 27. 14:46
반응형
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
using System;
 
namespace Application
{
    class MainClass
    {
        //카운트 다운
        //n : 10
        //result: 10 9 8 7 6 5 4 3 2 1 boom
 
        public static void Main(string[] args)
        {
            Console.WriteLine("카운트다운");
            var sol = new Solution();
            sol.solution(10);
        }
    }
 
    public class Solution {
        string str = "";
        public void solution(int n) { 
            if(n == 0) {
                str = "boom";
                Console.Write(str);
            }
            else {
                str = n + " ";
                Console.Write(str);
                solution(n - 1);
            }
        }
    }
}
 
 
 

반응형
: