Algorithm/CodeUp
[CodeUp_Java] Q1901 : 1부터 n까지 출력하기
Plitche
2022. 11. 29. 10:08
반응형
안녕하세요! Plitche(플리체)입니다.
이번 포스팅의 주제는 Q1901 : [기초-재귀함수] 1부터 n까지 출력하기 (자바, JAVA)입니다.
Intro
Question
문제 설명
입력
정수 n이 입력된다(1<=n<=200)
출력
1부터 n까지 한 줄에 하나씩 출력한다.
예시
- 입력 : 10
- 출력 :
1
2
3
4
5
6
7
8
9
10
Solution (풀이)
- 풀이 : 메모리 11196, 시간 : 61
public class Answer1 {
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int count = Integer.parseInt(br.readLine());
loop(1, count);
System.out.println(sb);
}
public static void loop(int index, int count) {
if (index <= count) {
sb.append(index + "\n");
loop(index+1, count);
} else {
return;
}
}
}
Ranking(순위)
반응형