알고리즘/백준
[백준 2446번 ː 자바(JAVA)] 별 찍기 - 9
그릿er
2020. 4. 21. 21:50
<문제>
첫째 줄부터 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
28
29
30
31
32
33
34
|
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
for(int i=0; i<num; i++) {
for(int j=0; j<i; j++) {
System.out.print(" ");
}
for(int s=num*2-i*2-1; s>0; s--) {
System.out.print("*");
}
System.out.println();
}
for(int i=num-1; i>0; i--) {
for(int j=i-1; j>0; j--) {
System.out.print(" ");
}
for(int s=i-1; s<num*2-i; s++) {
System.out.print("*");
}
System.out.println();
}
}
}
|