본문 바로가기
알고리즘/백준

[백준 2523번 ː 자바(JAVA)] 별 찍기 - 13

by 그릿er 2020. 4. 21.

 

<문제>

 

첫째 줄부터 2×N-1번째 줄까지 차례대로 별을 출력한다.

 

 

<예제>

 

 

 

 

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
import java.util.*;
 
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        for(int i=1; i<=num; i++) {
            for(int j=0; j<i; j++) {
                System.out.print("*");
            }
            System.out.println();
           }
        for(int i=1; i<num; i++) {
            for(int j=num-i; j>0; j--) {
                System.out.print("*");
            }
            System.out.println();
        }
        
        }
        
    }