happy coding
[java] 2742. 기찍 N 본문
문제
자연수 N이 주어졌을 때, N부터 1까지 한 줄에 하나씩 출력하는 프로그램을 작성하시오.
입력
첫째 줄에 100,000보다 작거나 같은 자연수 N이 주어진다.
출력
첫째 줄부터 N번째 줄 까지 차례대로 출력한다.
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
while (N >= 1) {
System.out.println(N);
N--;
}
}
}
반복문에는 while 도 있고, for도 있으니 그 두 가지에 대해서 풀어보았다.
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
for (int i=N ; i>0 ; i--) {
System.out.println(i);
}
}
}
'coding study > baekjoon' 카테고리의 다른 글
[java] 11720. 숫자의 합 (0) | 2023.08.19 |
---|---|
[java] 3046. R2 (0) | 2023.08.19 |
[java] 2439. 별 찍기 - 2 (0) | 2023.08.19 |
[java] 2442. 별 찍기 - 5 (0) | 2023.08.19 |
[java] 11721. 열 개씩 끊어 출력하기 (0) | 2023.08.19 |
Comments