728x90
๋ฐ˜์‘ํ˜•

2438. ๋ณ„ ์ฐ๊ธฐ - 1

๋ฌธ์ œ

์ฒซ์งธ ์ค„์—๋Š” ๋ณ„ 1๊ฐœ, ๋‘˜์งธ ์ค„์—๋Š” ๋ณ„ 2๊ฐœ, N๋ฒˆ์งธ ์ค„์—๋Š” ๋ณ„ N๊ฐœ๋ฅผ ์ฐ๋Š” ๋ฌธ์ œ

์ž…๋ ฅ

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

์ถœ๋ ฅ

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

 

- Scanner๋ฌธ ์‚ฌ์šฉ 

import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
        sc.close();
		
		
		for (int i =1; i<=N; i++) {
			for (int j = 1; j <= i; j++) {
				System.out.print("*");
			}
		System.out.println();
		} 
	}
}

 

N๊ฐœ์˜ ์ค„์— N๊ฐœ์˜ ๋ณ„์ด ๋‚˜์™€์•ผ ํ•˜๋ฏ€๋กœ ์ด์ค‘ ํฌ๋ฌธ์„ ๋Œ๋ ค์ฃผ๊ณ  ๋„์›Œ์ค˜์•ผํ•˜๋‹ˆ๊นŒ

N๊ฐœ์˜ ์ค„์— ํ•ด๋‹นํ•˜๋Š” ํฌ๋ฌธ์œผ๋กœ ๋‚˜์™€์„œ println()์„ ๋„ฃ์–ด์คฌ์Šต๋‹ˆ๋‹ค~~~

๋ณ„์ฐ๊ธฐ --2 ๋ฒˆ์€ BufferedReader/BufferWriter ์จ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค

 

 


2439. ๋ณ„ ์ฐ๊ธฐ - 2

๋ฌธ์ œ

์ฒซ์งธ ์ค„์—๋Š” ๋ณ„ 1๊ฐœ, ๋‘˜์งธ ์ค„์—๋Š” ๋ณ„ 2๊ฐœ, N๋ฒˆ์งธ ์ค„์—๋Š” ๋ณ„ N๊ฐœ๋ฅผ ์ฐ๋Š” ๋ฌธ์ œ

ํ•˜์ง€๋งŒ, ์˜ค๋ฅธ์ชฝ์„ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•œ ๋ณ„(์˜ˆ์ œ ์ฐธ๊ณ )์„ ์ถœ๋ ฅํ•˜์‹œ์˜ค.

์ž…๋ ฅ

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

์ถœ๋ ฅ

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

import java.io.*;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		StringTokenizer st;
		int N = Integer.parseInt(br.readLine());
		br.close();
		
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N - i; j++) {
				bw.write(' ');
			}
			for (int k = 1; k <= i; k++) {
				bw.write('*');
			}
			bw.newLine();
		}
		bw.flush();
		bw.close();
	}
}

 

์ €๋ฒˆ์— import java.io.*;์„ ์‚ฌ์šฉ์„ ๋ชปํ–ˆ์—ˆ๋Š”๋ฐ ์•Œ๊ณ  ๋ณด๋‹ˆ๊นŒ *์ „์— ๋งˆ์ง€๋ง‰ .์„ ์•ˆ ์ฐ์—ˆ๋”๋ผ๊ตฌ์š”...

์ง„์งœ import ๋„ˆ๋ฌด ๋งŽ์•„๊ฐ€์ง€๊ณ  ๋‹ค ์ ๊ธฐ ๊ท€์ฐฎ์•„์„œ ๋‹ค์‹œ ํ•œ๋ฒˆ ์‹œ๋„ํ•ด๋ดค๋Š”๋ฐ ๋นจ๊ฐ„์ค„ ์•ˆ ๋– ์„œ ๋จธ์“ฑํ–ˆ์Šต๋‹ˆ๋‹ค ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹

 

๊ณต๋ฐฑ ์ถœ๋ ฅ๊นŒ์ง€๋Š” ์‰ฌ์› ๋Š”๋ฐ ๋‹ค์Œ์„ ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ์ง€ ๊ณ ๋ฏผ์ด์—ˆ๋Š”๋ฐ ๋ช‡๋ฒˆ์˜ ์ด์ƒํ•œ ๋ณ„ ์ฐ๊ธฐ ๋์—

๋‹ค์‹œ ํ•œ๋ฒˆ for๋ฌธ์„ ๋Œ๋ฆฌ๋‹ˆ๊นŒ ์™„์„ฑ๋˜์—ˆ๋‹ค~~~

 

๋“œ๋””์–ด ๋ฐ˜๋ณต๋ฌธ ๋‘๋ฌธ์ œ ๋‚จ์•˜๋„ค์—ฌ... ๋ฐฐ์—ด๋„ ํ™”์ดํŒ…๐Ÿ’ช๐Ÿ’ช๐Ÿ’ช

 

728x90
๋ฐ˜์‘ํ˜•

+ Recent posts