매일 Algorithm

신재원·2023년 1월 25일
0

Algorithm

목록 보기
17/243

백준 2738번 행렬 덧셈


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        // 입력한 숫자대로 배열생성
        int[][] arr = new int[a][b];

        // '2'로 조건을 건이유 입력한 숫자가 2개임으로 배열은 2차원배열이다,
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < a; j++) {
                for (int k = 0; k < b; k++) {
                    arr[j][k] += sc.nextInt();
                }
            }
        }

        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }
}

0개의 댓글