01-25 18:49
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

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

Algorithm/Baekjoon

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

miinsun 2022. 3. 11. 18:26

 

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

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

 

 

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

์ž…๋ ฅ 

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

 

์ถœ๋ ฅ

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

 

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

1

 

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

*

 

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

2

 

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

 *
***

 

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

3

 

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

  *
 * *
*****

 

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

4

 

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

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

 

 

 

๐Ÿ’ป  Main.java

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