본문 바로가기
Algorithm/Beakjoon

[Java] baekjoon 2741 : N 찍기 / for문

by Amy97 2021. 8. 2.
728x90

문제 


https://www.acmicpc.net/problem/2741

 

2741번: N 찍기

자연수 N이 주어졌을 때, 1부터 N까지 한 줄에 하나씩 출력하는 프로그램을 작성하시오.

www.acmicpc.net

구현 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            System.out.println(i);
        }
 
    }
}
cs

결과 


728x90

댓글