백준 알고리즘

3. 반복문 - 9 (2438번)

IT의 큰손 2023. 3. 1. 12:31
728x90

★ 문제

  • 첫째 줄에는 별 1개, 둘째 줄에는 별 2개, N번째 줄에는 별 N개를 찍는 문제
  • 첫째 줄부터 N번째 줄까지 차례대로 별을 출력한다
*
**
***
****
*****

★ 소스코드

  •  
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		
		int num = scan.nextInt();
		String result = "*";
		
		for(int i=0; i<num; i++) {
			System.out.println(result);
			result += "*";
		}
	}

}
728x90