-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmatrix.java
More file actions
64 lines (50 loc) · 1.08 KB
/
matrix.java
File metadata and controls
64 lines (50 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.*;
class matrix{ // import 하기 귀찮음 import 할사람은 구분해서 하셈
int col;
int raw;
int matrix[][];
public matrix(){
col = 10;
raw = 10;
matrix = new int[col][raw];
random(col, raw, 10, -10);
}
void random(int a, int b, int min, int max){
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){
int tmp = (int)(Math.random()*(max - min));
tmp += min;
matrix[i][j] = tmp;
}
}
}
public void addMatrix(int[][] arr){
System.out.println("=================");
if(col != arr.length){
System.out.println("Err");
}
if(raw != arr[0].length){
System.out.println("Err");
}
if(col == arr.length && raw == arr[0].length){
for(int i=0;i<col;i++){
for(int j=0;j<raw;j++){
matrix[i][j] = matrix[i][j] + arr[i][j];
}
}
for(int i=0;i<col;i++){
for(int j=0;j<raw;j++){
System.out.printf("%d ",matrix[i][j]);
}
System.out.println("");
}
}
}
}
public class matrix{
public static void main(String[] args){
matrix a = new matrix();
matrix b = new matrix();
a.addMatrix(b.matrix);
}
}