/*

 * http://tryhelloworld.co.kr/challenge_codes/7

 */

class SumMatrix {

int[][] sumMatrix(int[][] A, int[][] B) {

int[][] answer = new int[2][2];

int sum=0;

int n=0;

int num1[] = new int[4];

int num2[] = new int[4];


for(int i=0; i<2; i++){

for(int j=0; j<2; j++){

num1[sum]=A[i][j];

num2[sum]=B[i][j];

sum++;

}

}

for(int i=0; i<2; i++){

for(int j=0; j<2; j++){

answer[i][j]=num1[n]+num2[n];

n++;

System.out.println(answer[i][j]);

}

}

return answer;

}


// 아래는 테스트로 출력해 보기 위한 코드입니다.

public static void main(String[] args) {

SumMatrix c = new SumMatrix();

int[][] A = { { 1, 2 }, { 2, 3 } };

int[][] B = { { 3, 4 }, { 5, 6 } };

int[][] answer = c.sumMatrix(A, B);

if (answer[0][0] == 4 && answer[0][1] == 6 && 

answer[1][0] == 7 && answer[1][1] == 9) {

System.out.println("맞았습니다. 제출을 눌러 보세요");

} else {

System.out.println("틀렸습니다. 수정하는게 좋겠어요");

}

}

}

'알고리즘 풀이' 카테고리의 다른 글

Level 2 2016년  (0) 2017.03.30
Level 2 최솟값 만들기  (0) 2017.03.30
Level 1 스트링을 숫자로 바꾸기  (0) 2017.03.30
Level 1 가운데 글자 가져오기  (0) 2017.03.30
Level 1 최대값과 최소값  (0) 2017.03.30

+ Recent posts