말랑한 하루

[SW Expert Academy] 2005 파스칼의 삼각형 [Java] 본문

문제풀이/SWexpert Academy

[SW Expert Academy] 2005 파스칼의 삼각형 [Java]

지수는말랑이 2021. 1. 21. 21:56
반응형

[ 핵심풀이 ]

[ 핵심소스 ]

[ Java ]

import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int tc = sc.nextInt();
        for (int t = 1; t <= tc; t++) {
            int triangle = sc.nextInt();

            System.out.println("#"+t);
			
            int ary[][] = new int[triangle][triangle];
            ary[0][0]=1;
            System.out.println(ary[0][0]);
            for(int i=1;i<triangle;i++) {
                ary[i][0]=ary[i-1][0];
                System.out.print(ary[i][0]+" ");
                for(int j=1;j<=i;j++) {
                    ary[i][j]=ary[i-1][j-1]+ary[i-1][j];
                    System.out.print(ary[i][j]+" ");
				}
                System.out.println();
            }
        }
        sc.close();
    }
}
반응형
Comments