Notice
Recent Posts
Link
- Today
- Total
hye-log
[정올]1329번 별삼각형3(JAVA) 본문
0. 문제 링크
https://www.jungol.co.kr/problem/1329
JUNGOL
history 최근 본 문제
www.jungol.co.kr
1. 문제 설명
1) 다음과 같은 모양을 출력하기

2. 입출력
// input
7
// output
*
***
*****
*******
*****
***
*
3. 코드
import java.util.*;
public class jol1329 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if(!(n > 0 && n <= 100 && n % 2 == 1)) {
System.out.println("INPUT ERROR!");
return;
}
int stars = 1;
int blanks = 0;
for(int i = 0; i < n; i++) {
for(int b = 0; b < blanks; b++) {
System.out.print(" ");
}
if(i < (n/2)) {
for(int j = 0; j < n; j++) {
if(j < stars) {
System.out.print("*");
}
}
stars += 2;
blanks++;
}
else {
for(int j = 0; j < n; j++) {
if(j < stars) {
System.out.print("*");
}
}
stars -= 2;
blanks--;
}
System.out.println();
}
}
}
실행 결과

4. 회고
1) " "과 "*"이 출력되는 경우 나누기
5. Github
https://github.com/iihye/Algorithm/blob/main/Jungol/jol1329.java
728x90
'CodingTest > Jungol' 카테고리의 다른 글
[정올]1707번 달팽이사각형(JAVA) (0) | 2023.07.29 |
---|---|
[정올]1719번 별삼각형2(JAVA) (0) | 2023.07.29 |
[정올]1523번 별삼각형1(JAVA) (0) | 2023.07.29 |