반응형
2438번 1
출력
5
*
**
***
****
*****
코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int i = 0; i <n; i++) {
for (int j = 0; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
2439번 2
출력
5
*
**
***
****
*****
코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= i; k++) {
System.out.print("*");
}
System.out.println();
}
}
}
2440번 3
출력
5
*****
****
***
**
*
코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int j = 0; j < n; j++) {
for (int i = 0; i < n - j; i++) {
System.out.print("*");
}
System.out.println();
}
}
}
2441번 4
출력
5
*****
****
***
**
*
코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int i = 0; i < n; i++) {
for (int k = 0; k < i; k++) {
System.out.print(" ");
}
for (int j = n - i; j > 0; j--) {
System.out.print("*");
}
System.out.println();
}
}
}
2442번 5
출력
5
*
***
*****
*******
*********
코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int i = 0; i < n; i++) {
for (int k = n - 1; k > i; k--) {
System.out.print(" ");
}
for (int j = 0; j < i * 2 + 1; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
2443번 6
출력
5
*********
*******
*****
***
*
코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int i = n; i > 0; i--) {
for (int k = n; k > i; k--) {
System.out.print(" ");
}
for (int j = 0; j < i * 2 - 1; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
2444번 7
출력
5
*
***
*****
*******
*********
*******
*****
***
*
코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int cnt = scanner.nextInt();
for (int i = 0; i < cnt; i++) {
for (int k = cnt - 1; k > i; k--) {
System.out.print(" ");
}
for (int j = 0; j < i * 2 + 1; j++) {
System.out.print("*");
}
System.out.println();
}
for (int i = cnt - 1; i > 0; i--) {
for (int k = cnt; k > i; k--) {
System.out.print(" ");
}
for (int j = 0; j < i * 2 - 1; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
2445번 8
출력
* *
** **
*** ***
**** ****
**********
**** ****
*** ***
** **
* *
코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int cnt = scanner.nextInt();
for (int i = 0; i < cnt; i++) {
for (int k = 0; k < i + 1; k++) {
System.out.print("*");
}
for (int j = 0; j < 2 * (cnt - i - 1); j++) System.out.print(" ");
for (int k = 0; k < i + 1; k++) {
System.out.print("*");
}
System.out.println();
}
for (int i = cnt - 1; i > 0; i--) {
for (int k = 0; k < i; k++) {
System.out.print("*");
}
for (int j = 0; j < 2 * (cnt - i); j++) System.out.print(" ");
for (int k = 0; k < i; k++) {
System.out.print("*");
}
System.out.println();
}
}
}
2446번 9
출력
5
*********
*******
*****
***
*
***
*****
*******
*********
코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int cnt = scanner.nextInt();
for (int i = cnt; i > 0; i--) {
for (int j = 0; j < cnt - i; j++) {
System.out.print(" ");
}
for (int j = 0; j < i * 2 - 1; j++) {
System.out.print("*");
}
System.out.println();
}
for (int i = 0; i < cnt - 1; i++) {
for (int k = cnt - 2; k > i; k--) {
System.out.print(" ");
}
for (int j = 0; j < i * 2 + 3; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
2522번 12
출력
5
*
**
***
****
*****
****
***
**
*
코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - i - 1; j++) {
System.out.print(" ");
}
for (int j = 0; j < i + 1; j++) {
System.out.print("*");
}
System.out.println();
}
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < i + 1; j++) {
System.out.print(" ");
}
for (int j = 0; j < n - i - 1; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
2523번 13
출력
5
*
**
***
****
*****
****
***
**
*
코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < i + 1; j++) {
System.out.print("*");
}
System.out.println();
}
for (int i = n - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
반응형
'코딩 테스트 > [JAVA] 백준' 카테고리의 다른 글
[JAVA] 백준 2754번 학점계산 | BOJ 백준 bronze 3 (0) | 2022.03.18 |
---|---|
[JAVA] 백준 2547번 사탕 선생 고창영 | BOJ 자바 (0) | 2022.03.18 |
[JAVA] 백준 1598번 꼬리를 무는 숫자 나열 | BOJ 자바 bronze 3 (0) | 2022.03.15 |
[JAVA] 백준 1373번 2진수 8진수 (0) | 2022.03.15 |
[JAVA] 백준 8674번 Tabliczka (0) | 2022.03.10 |
댓글