[프로그래머스]행렬의 덧셈

mongs_Develop·2022년 4월 26일
0

Programmers-Level1-Java

목록 보기
3/30
post-thumbnail
  • 문제 & 예시
  • 소스코드
import java.util.Arrays;

// 행렬의 덧셈
public class test03 {
	public static void main(String[] args) {
		Solution3 sol = new Solution3();
		int[][] arr1 = {{1,2}, {2,3}};
		int[][] arr2 = {{3,4}, {5,6}};
		
		System.out.println(sol.solution(arr1, arr2));
	}

}

class Solution3 {
    public int[][] solution(int[][] arr1, int[][] arr2) {
        int[][] answer = new int[arr1.length][arr1[0].length];
        
        for(int i =0;i<answer.length;i++) {
        	for(int j=0;j<answer[i].length;j++) {
        		answer[i][j] = arr1[i][j] + arr2[i][j];  		
        	}
        	System.out.println(Arrays.deepToString(answer));
        }
        return answer;
    }
}
  • consol
profile
개 발 인생

0개의 댓글