-
Notifications
You must be signed in to change notification settings - Fork 0
/
jol1523.java
49 lines (46 loc) · 1.04 KB
/
jol1523.java
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.Scanner;
public class jol1523 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
if(n > 100 || m < 0 || m > 3) {
System.out.println("INPUT ERROR!");
return;
}
switch(m) {
case 1: // 왼쪽 위에서 아래로 차례로 증가
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
break;
case 2: // 왼쪽 위에서 아래로 차례로 감소
for(int i = 1; i <= n; i++) {
for(int j = 0; j < (n-i+1); j++) {
System.out.print("*");
}
System.out.println();
}
break;
case 3: // 가운데에서 아래로 차례로 증가
int left = (n*2-1) / 2;
int right = (n*2-1) / 2;
for(int i = 1; i <= n; i++) {
for(int j = 0; j < (n*2-1); j++) {
if(j >= left && j <= right) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
left--;
right++;
System.out.println();
}
break;
}
}
}