01-10 22:36
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[BAEKJOON] ๋ฐฑ์ค€ ์ž…์ถœ๋ ฅ 2446 :: ๋ณ„ ์ฐ๊ธฐ - 8 JAVA ๋ณธ๋ฌธ

Algorithm/Baekjoon

[BAEKJOON] ๋ฐฑ์ค€ ์ž…์ถœ๋ ฅ 2446 :: ๋ณ„ ์ฐ๊ธฐ - 8 JAVA

miinsun 2022. 3. 11. 17:50

 

๐Ÿ’ฌ  ๋ฌธ์ œ ์„ค๋ช…

์˜ˆ์ œ๋ฅผ ๋ณด๊ณ  ๊ทœ์น™์„ ์œ ์ถ”ํ•œ ๋’ค์— ๋ณ„์„ ์ฐ์–ด ๋ณด์„ธ์š”.

 

 

๐Ÿ”จ  ์ž…์ถœ๋ ฅ ์˜ˆ

์ž…๋ ฅ 

  • ์ฒซ์งธ ์ค„์— N(1 ≤ N ≤ 100)์ด ์ฃผ์–ด์ง„๋‹ค.
 

 

์ถœ๋ ฅ

  • ์ฒซ์งธ ์ค„๋ถ€ํ„ฐ 2×N-1๋ฒˆ์งธ ์ค„๊นŒ์ง€ ์ฐจ๋ก€๋Œ€๋กœ ๋ณ„์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 1)

5

 

์˜ˆ์ œ ์ถœ๋ ฅ 1)

*********
 *******
  *****
   ***
    *
   ***
  *****
 *******
*********

 

 

 

๐Ÿ’ป  Main.java

/* ๋ฐฑ์ค€ ์ž…์ถœ๋ ฅ - 2446 :: ๋ณ„์ฐ๊ธฐ - 9 */
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 = 0; j < i - 1; j++) System.out.print(" ");
			for(int j = 0; j < 2 * n - 2 * i + 1; j++) System.out.print("*");
			System.out.println();
			}
		 
		for(int i = 1; i < n; i++){
			for(int j = 0; j < n - i - 1; j++) System.out.print(" ");
			for(int j = 0; j < 2 * i + 1; j++) System.out.print("*");
			System.out.println();
			}
		
		sc.close();
	}
}
Comments