public static void main(String[] args) {
for (int i = 1; i < 5; i++) {
for (int j = 0; j < 4 - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= (2 * i) - 1; k++) {
System.out.print(i);
}
System.out.println();
}
}
Short Coding chatGPT가 짜줌 ㅎ
public static void main(String[] args) {
for (int i = 1; i < 5; i++) {
// Create a string with leading spaces
String spaces = " ".repeat(4 - i);
// Create a string with the 'i' value repeated (2 * i - 1) times
String numbers = String.valueOf(i).repeat(2 * i - 1);
// Combine the spaces and numbers strings and print
System.out.println(spaces + numbers);
}
}
'자바 입문 기초 알고리즘 구조' 카테고리의 다른 글
자바 제너릭(4/5) 생활코딩 (0) | 2021.07.22 |
---|---|
자바 제네릭 2 (생활코딩) (0) | 2021.07.22 |
인스턴스화 시키는 법 (0) | 2021.07.22 |
제너릭 메소드 (생활코딩) (0) | 2021.07.22 |
별찍기 왼쪽아래가 직각인 삼각형 왼쪽위가 직각인 삼각형 (0) | 2021.07.16 |