별찍기 -8
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i=1; i<n+1; i++) {
for(int k=0; k<i; k++) System.out.print("*");
for(int j=(n*2)-(i*2); j>0; j--) System.out.print(" ");
for(int k=0; k<i; k++) System.out.print("*");
System.out.println();
}
for(int i=4; i>0; i--) {
for(int k=i; k>0; k--) System.out.print("*");
for(int j=1; j<=(n*2)-(i*2); j++) System.out.print(" ");
for(int k=i; k>0; k--) System.out.print("*");
System.out.println();
}
sc.close();
}
}
잘돌아가는데 왜 틀렸다하누,,
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i=1; i<=n; i++) {
for(int j=1; j<=i; j++) System.out.print("*");
for(int k=n-i; k>0; k--) System.out.print(" ");
for(int k=n-i; k>0; k--) System.out.print(" ");
for(int j=1; j<=i; j++) System.out.print("*");
System.out.println();
}
for(int i=n-1; i>0; i--) {
for(int j=i; j>0; j--) System.out.print("*");
for(int k=1; k<=n-i; k++)System.out.print(" ");
for(int k=1; k<=n-i; k++)System.out.print(" ");
for(int j=i; j>0; j--) System.out.print("*");
System.out.println();
}
sc.close();
}
}
위아래 각 4파트로 나눠야 돌아가나봄 ㅎㅎ;;
정말 모르겠다 백준의 기준
'PROGRAMMING CODE > JAVA' 카테고리의 다른 글
[BAEKJOON] No.2522 JAVA (0) | 2021.10.14 |
---|---|
[BAEKJOON] No.2446 JAVA (0) | 2021.10.14 |
[BAEKJOON] No.2444 JAVA (0) | 2021.10.14 |
[BAEKJOON] No.2884 JAVA (0) | 2021.10.14 |
[BAEKJOON] No.1000 JAVA (0) | 2021.10.14 |