본문 바로가기

프로그래밍/알고리즘(자바)

행렬의 덧셈 Level 1

행렬의 덧셈 Level 1


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    int[][] sumMatrix(int[][] A, int[][] B) {
 
    int row = A.length//행의 길이
    int col = A[0].length// 열의 길이
 
 
    int[][] answer = new int[row][col];
    for(int i = 0 ; i<row; i++){
      for(int j =0 ; j<col; j++){
        answer[i][j] = A[i][j] + B[i][j];
      }
    }
        return answer;
    }
 
 
#행렬 순서
 
[0][0]    [0][1
 
[1][0]    [1][1]
 
cs