(백준/Java) 별 찍기 모음 (1,3,5,7,9,13,15,17,21)

2021. 5. 28. 16:03·CodingTest
별 찍기 - 1 ~ 별 찍기 - 17

난이도: Bronze 3

프로그래밍 언어: Java

 

별 찍기 - 21

난이도: Bronze 2

프로그래밍 언어: Java

 

푼일자: 2021년 5월

 

별 찍기 - 1 : https://www.acmicpc.net/problem/2438

별 찍기 - 3 : https://www.acmicpc.net/problem/2440

별 찍기 - 5 : https://www.acmicpc.net/problem/2442

별 찍기 - 7 : https://www.acmicpc.net/problem/2444

별 찍기 - 9 : https://www.acmicpc.net/problem/2446

별 찍기 - 13 : https://www.acmicpc.net/problem/2523

별 찍기 - 15 : https://www.acmicpc.net/problem/10990

별 찍기 - 17 : https://www.acmicpc.net/problem/10990

별 찍기 - 21 : https://www.acmicpc.net/problem/10996

 

[2438번] 별 찍기 - 1

1
2
3
4
5
6
7
8
9
10
11
12
public class question_2438 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
 
        for (int i = 0; i < a; i++) {
            StringBuilder sb = new StringBuilder();
            for (int t = 0; t <= i; t++) sb.append("*");
            System.out.println(sb);
        }
    }
}
Colored by Color Scripter
cs

 

[2440번] 별 찍기 - 3

1
2
3
4
5
6
7
8
9
10
11
12
public class question_2440 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
 
        for (int i = a; i > 0; i--) {
            StringBuilder sb = new StringBuilder();
            for (int t = i; t > 0; t--) sb.append("*");
            System.out.println(sb);
        }
    }
}
Colored by Color Scripter
cs

 

[2442번] 별 찍기 - 5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class question_2442 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
 
        for (int i = 0; i < a; i++) {
            System.out.printf(getStackString(a - i - 1, " "));
            System.out.println(getStackString(i * 2 + 1, "*"));
        }
    }
 
    public static String getStackString(int count, String str) {
        StringBuilder sb = new StringBuilder();
        while(count-- > 0) sb.append(str);
        return sb.toString();
    }
}
Colored by Color Scripter
cs

 

[2444번] 별 찍기 - 7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class question_2444 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
 
        Stack<String> stack = new Stack<>();
        for (int i = 0; i < a; i++) {
            stack.add(getStackString(a - i - 1, " ") + getStackString(i * 2 + 1, "*"));
            System.out.println(stack.peek());
        }
        while(stack.size() != 1) {
            stack.pop();
            System.out.println(stack.peek());
        }
    }
 
    public static String getStackString(int count, String str) {
        StringBuilder sb = new StringBuilder();
        while(count-- > 0) sb.append(str);
        return sb.toString();
    }
}
Colored by Color Scripter
cs

 

[2446번] 별 찍기 - 9

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class question_2446 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
 
        Stack<String> stack = new Stack<>();
        for (int i = 0; i < a; i++) {
            stack.add(getStackString(i, " ") + getStackString((a - i) * 2 -1, "*"));
            System.out.println(stack.peek());
        }
        while(stack.size() != 1) {
            stack.pop();
            System.out.println(stack.peek());
        }
    }
 
    public static String getStackString(int count, String str) {
        StringBuilder sb = new StringBuilder();
        while(count-- > 0) sb.append(str);
        return sb.toString();
    }
}
Colored by Color Scripter
cs

 

[2523번] 별 찍기 - 13

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class question_2523 { // 별 찍기 - 13
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
 
        Stack<String> stack = new Stack<>();
        for (int i = 0; i < a; i++) {
            StringBuilder sb = new StringBuilder();
            for (int t = 0; t <= i; t++) sb.append("*");
            stack.add(sb.toString());
            System.out.println(stack.peek());
        }
        while(stack.size() != 1) {
            stack.pop();
            System.out.println(stack.peek());
        }
    }
}
Colored by Color Scripter
cs

 

[10990번] 별 찍기 - 15

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class question_10990 { // 별 찍기 - 15
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
 
        for (int i = 0; i < a; i++) {
            System.out.printf(getStackSpace(a - i - 1));
            if (i == 0) System.out.println("*");
            else System.out.println("*" + getStackSpace(i * 2 - 1) + "*");
        }
    }
 
    public static String getStackSpace(int count) {
        StringBuilder sb = new StringBuilder();
        while(count-- > 0) sb.append(" ");
        return sb.toString();
    }
}
Colored by Color Scripter
cs

 

[10992번] 별 찍기 - 17

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public class question_10992 { // 별 찍기 - 17
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
 
        for (int i = 0; i < a; i++) {
            System.out.printf(getStackSpace(a - i - 1, " "));
            if (i == 0) System.out.println("*");
            else if (i == a - 1) System.out.println(getStackSpace(i * 2 + 1, "*"));
            else System.out.println("*" + getStackSpace(i * 2 - 1, " ") + "*");
        }
    }
 
    public static String getStackSpace(int count, String str) {
        StringBuilder sb = new StringBuilder();
        while(count-- > 0) sb.append(str);
        return sb.toString();
    }
}
Colored by Color Scripter
cs

 

[10996번] 별 찍기 - 21

1
2
3
4
5
6
7
8
9
10
11
12
13
public class question_10996 { // 별 찍기 - 21
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
 
        for (int i = 0; i < a * 2; i++) {
            for (int t = 0; t < a; t++)
                if ((i + t) % 2 == 0) System.out.printf("*");
                else System.out.printf(" ");
            System.out.printf("\n");
        }
    }
}
Colored by Color Scripter
cs

 

 

끝 !

반응형
저작자표시 비영리 (새창열림)
'CodingTest' 카테고리의 다른 글
  • (백준/Kotlin) 2839번 : 설탕 배달(해설)
  • (백준/Kotlin) 11050번 : 이항 계수 1
  • (백준/Java) 15947번 : 아기 석환 뚜루루 뚜루
  • (프로그래머스/Java) 짝지어 제거하기
Kua
Kua
정보 공유, 개인 정리 공간 입니다.
  • Kua
    Kua's Miscellaneous
    Kua
    • 분류 전체보기 (185)
      • 대문 (2)
      • Tips (25)
        • Chrome (2)
        • Windows (4)
        • IDE (3)
        • 기타 (16)
      • CodingTest (44)
      • Language (20)
        • PHP (5)
        • C# (7)
        • Java (1)
        • Kotlin (7)
      • Framework & Runtime (16)
        • SpringBoot (12)
        • Node.js (2)
        • Vue.js (1)
        • Gradle (1)
      • DevOps (13)
        • Linux (1)
        • Docker (4)
        • Kubernetes (2)
        • Apache Kafka (1)
        • AWS (1)
      • 일상다반사 (53)
        • 도서 (1)
        • 개발 (8)
        • 후기 - IT (7)
        • 후기 - 일상 (13)
        • 차가리 (4)
        • 방송통신대학교 (4)
        • 음식 (2)
      • Games (12)
        • Minecraft (7)
        • VR (2)
        • 그외 (3)
  • 최근 글

  • 인기 글

  • 태그

    Algorithm
    minecraft
    bronze2
    c#
    Spring Boot
    알고리즘
    bronze1
    Plugin
    후기
    백준
    spring
    Silver5
    github
    갤럭시
    java
    error
    Kotlin
    Windows
    codingtest
    코딩테스트
  • 전체
    오늘
    어제
  • hELLO· Designed By정상우.v4.10.0
Kua
(백준/Java) 별 찍기 모음 (1,3,5,7,9,13,15,17,21)
상단으로

티스토리툴바