SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.Scanner;
import java.io.FileInputStream;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T=sc.nextInt();
for(int test_case = 1; test_case <= T; test_case++)
{
int N=sc.nextInt();
int [][]Triangle = new int[N][N];
System.out.println("#" + test_case);
for (int i =0; i <N; i++){
for( int j = 0; j<=i; j++){
if(i==j)
Triangle[i][j] = 1;
else if(j==0)
Triangle[i][j] =1;
else
Triangle[i][j] = Triangle[i-1][j-1] + Triangle[i-1][j];
System.out.print(Triangle[i][j] + " ");
}
System.out.println();
}
}
}
}
2차원 배열 선언, 삼각형의 좌우 끝일땐 1 고정, 그 외에는 요구한 대로 전 단계의 숫자들 더한 값 넣으면 됨
'SWEA' 카테고리의 다른 글
[SWEA] 초심자의 회문 검사 (0) | 2024.09.25 |
---|---|
[SWEA] 파리 퇴치 (0) | 2024.09.25 |
[SWEA] 패턴 마디의 길이 (0) | 2024.09.21 |
[SWEA] 간단한 369게임 (0) | 2024.09.20 |
[SWEA] += (1) | 2024.09.20 |