import java.util.Scanner;
public class ArrayTest4 {
public static void main(String[] args) {
int[][] matrix1 = { { 1, 2 }, { 3, 4 } };
// [2][2]
int[][] matrix2 = { { 3, 1 }, { 4, 2 } };
int[][] matrix3 = matrixSum(matrix1, matrix2);
int[][] matrix4 = matrixMul(matrix1, matrix2);
// 행렬 합
matrixPrint(matrix3);
// 행렬 출력
}
private static int[][] matrixMul(int[][] matrix1, int[][] matrix2) {
int[][] resultMatrix = new int[2][2];
for (int j = 0; j < 2; j++) {
for (int i = 0; i < 2; i++) {
resultMatrix[j][i] = matrix1[j][0] * matrix2[0][i]
+ matrix1[j][1] * matrix2[1][i];
}
}
return resultMatrix;
}
private static void matrixPrint(int[][] matrix4) {
for (int i = 0; i < 2; i++) {
System.out.print("{");
for (int j = 0; j < 2; j++) {
System.out.print(" " + matrix4[i][j] + " ");
}
System.out.println("}");
}
}
private static int[][] matrixSum(int[][] matrix1, int[][] matrix2) {
int[][] resultMatrix = new int[2][2];
for (int j = 0; j < 2; j++) {
for (int i = 0; i < 2; i++) {
resultMatrix[j][i] = matrix1[j][i] + matrix2[j][i];
}
}
return resultMatrix;
}
}
'Programming > JAVA,JSP' 카테고리의 다른 글
JAVA 제네릭 컬렉션 실습 (1) | 2014.01.09 |
---|---|
JAVA 객체지향 핵심 이론 (0) | 2014.01.07 |
JAVA 배열 정렬 예제 (0) | 2014.01.06 |
JAVA 행렬 합곱 예제 (0) | 2014.01.06 |
Java Calendar (0) | 2013.12.31 |