자바 피라미드

황희윤·2023년 9월 13일

피라미드 별찍기

public static void main(String[] args){
	int n = 4;
    for(int i = 1; i <= n; i++){
        for(int j=1; j <= n - i; j++)
            System.out.print(" ");
            
        for(int j = 1; j <= 2*i-1; j++)
            System.out.print("*");
            
        System.out.println();
     }
}

역피라미드

public static void main(String[] args) {
	int n = 4;
    for(int i = n; i > 0; i--){
        for(int j=0; j < n -i; j++)
            System.out.print(" ");

        for(int j = 0; j < 2*i - 1; j++)
            System.out.print("*");

        System.out.println();
    }
}
profile
HeeYun's programming study

0개의 댓글