Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9f61873

Browse files
committedFeb 20, 2023
Java Matrix Calculation
1 parent cb11966 commit 9f61873

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
 

‎For Coding Test/For Coding Test.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@
139139
</Link>
140140
</ItemDefinitionGroup>
141141
<ItemGroup>
142+
<ClCompile Include="Java Matrix.cpp" />
142143
<ClCompile Include="string parser.cpp" />
144+
<ClCompile Include="VSCode+Java.cpp" />
143145
</ItemGroup>
144146
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
145147
<ImportGroup Label="ExtensionTargets">

‎For Coding Test/For Coding Test.vcxproj.filters

+6
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,11 @@
1818
<ClCompile Include="string parser.cpp">
1919
<Filter>소스 파일</Filter>
2020
</ClCompile>
21+
<ClCompile Include="VSCode+Java.cpp">
22+
<Filter>소스 파일</Filter>
23+
</ClCompile>
24+
<ClCompile Include="Java Matrix.cpp">
25+
<Filter>소스 파일</Filter>
26+
</ClCompile>
2127
</ItemGroup>
2228
</Project>

‎For Coding Test/Java Matrix.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Çà·Ä µ¡¼À
2+
public class MatrixAddition {
3+
public static void main(String[] args) {
4+
int[][] a = { {1, 2}, {3, 4} };
5+
int[][] b = { {5, 6}, {7, 8} };
6+
7+
int rows = a.length;
8+
int columns = a[0].length;
9+
10+
int[][] result = new int[rows][columns];
11+
12+
for (int i = 0; i < rows; i++) {
13+
for (int j = 0; j < columns; j++) {
14+
result[i][j] = a[i][j] + b[i][j];
15+
}
16+
}
17+
18+
for (int i = 0; i < rows; i++) {
19+
for (int j = 0; j < columns; j++) {
20+
System.out.print(result[i][j] + " ");
21+
}
22+
System.out.println();
23+
}
24+
}
25+
}
26+
27+
// Çà·Ä °ö¼À
28+
public class MatrixMultiplication {
29+
public static void main(String[] args) {
30+
int[][] a = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
31+
int[][] b = { {9, 8, 7}, {6, 5, 4}, {3, 2, 1} };
32+
33+
int rows1 = a.length;
34+
int columns1 = a[0].length;
35+
int columns2 = b[0].length;
36+
37+
int[][] result = new int[rows1][columns2];
38+
39+
for (int i = 0; i < rows1; i++) {
40+
for (int j = 0; j < columns2; j++) {
41+
for (int k = 0; k < columns1; k++) {
42+
result[i][j] += a[i][k] * b[k][j];
43+
}
44+
}
45+
}
46+
47+
for (int i = 0; i < rows1; i++) {
48+
for (int j = 0; j < columns2; j++) {
49+
System.out.print(result[i][j] + " ");
50+
}
51+
System.out.println();
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)
Please sign in to comment.