백준 2738번 행렬 덧셈(java)

마뇽미뇽·2024년 5월 6일
0

알고리즘 문제풀이

목록 보기
62/165

1.문제

https://www.acmicpc.net/problem/2738

2.풀이

다차원 배열은 이중for문을 사용한다.

3.코드

package com.example.baekjoon;

import java.util.Scanner;

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        int arrA[][] = new int[n][m];
        int arrB[][] = new int[n][m];

        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                arrA[i][j] = sc.nextInt();
            }
        }

        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                arrB[i][j] = sc.nextInt();
            }
        }

        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                System.out.print((arrA[i][j] + arrB[i][j]) + " ");;
            }
            System.out.println();
        }
    }
}
profile
Que sera, sera

0개의 댓글