-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP002_BJ17478_재귀함수가뭔가요.java
More file actions
74 lines (56 loc) · 2.25 KB
/
P002_BJ17478_재귀함수가뭔가요.java
File metadata and controls
74 lines (56 loc) · 2.25 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.Scanner;
// dfs
public class P002_BJ17478_재귀함수가뭔가요 {
static int count;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
count = sc.nextInt();
System.out.println("어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다.\n"
+ "\"재귀함수가 뭔가요?\"\n"
+ "\"잘 들어보게. 옛날옛날 한 산 꼭대기에 이세상 모든 지식을 통달한 선인이 있었어.\n"
+ "마을 사람들은 모두 그 선인에게 수많은 질문을 했고, 모두 지혜롭게 대답해 주었지.\n"
+ "그의 답은 대부분 옳았다고 하네. 그런데 어느 날, 그 선인에게 한 선비가 찾아와서 물었어.\"");
function(count);
System.out.println("라고 답변하였지.");
}
public static void function(int n) {
if (n == 1) {
for(int i = 0; i < count; i++) {
System.out.print("____");
}
System.out.println("\"재귀함수가 뭔가요?\"");
for(int i = 0; i < count; i++) {
System.out.print("____");
}
System.out.println("\"재귀함수는 자기 자신을 호출하는 함수라네\"");
for(int i = 0; i < count; i++) {
System.out.print("____");
}
System.out.println("라고 답변하였지.");
count--;
return;
}
for(int i = 0; i < count - n + 1; i++) {
System.out.print("____");
}
System.out.println("\"재귀함수가 뭔가요?\"");
for(int i = 0; i < count - n + 1; i++) {
System.out.print("____");
}
System.out.println("\"잘 들어보게. 옛날옛날 한 산 꼭대기에 이세상 모든 지식을 통달한 선인이 있었어.");
for(int i = 0; i < count - n + 1; i++) {
System.out.print("____");
}
System.out.println("마을 사람들은 모두 그 선인에게 수많은 질문을 했고, 모두 지혜롭게 대답해 주었지.");
for(int i = 0; i < count - n + 1; i++) {
System.out.print("____");
}
System.out.println("그의 답은 대부분 옳았다고 하네. 그런데 어느 날, 그 선인에게 한 선비가 찾아와서 물었어.\"");
function(n - 1);
for(int i = 0; i < count; i++) {
System.out.print("____");
}
count--;
System.out.println("라고 답변하였지.");
}
}