-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray2D.java
More file actions
44 lines (37 loc) · 1.33 KB
/
Array2D.java
File metadata and controls
44 lines (37 loc) · 1.33 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
import java.lang.reflect.Array;
public class Array2D {
public static void main(String[] args) {
int arr[][]= {
{0,2,4},
{6,8,10},
{12,14,16}
};
System.out.println("The 3x3 Matrix: ");
for (int i=0; i<arr.length; i++) {
for (int j=0; j<arr[i].length; j++) {
if (Integer.toString(arr[i][j]) == 1) {
System.out.print(arr[i][j]+" ");
}
else if (Integer.toString(arr[i][j]) == 2) {
System.out.print(arr[i][j]+" ");
}
}
System.out.println();
}
System.out.println();
int det = (
(arr[1-1][1-1] * (
(arr[2-1][2-1]*arr[3-1][3-1]) - (arr[2-1][3-1]*arr[3-1][2-1])
)) -
(arr[1-1][2-1] * (
(arr[2-1][1-1]*arr[3-1][3-1]) - (arr[3-1][1-1]*arr[2-1][3-1])
)) +
(arr[1-1][3-1] * (
(arr[2-1][1-1]*arr[3-1][2-1]) - (arr[2-1][2-1]*arr[3-1][1-1])
))
);
System.out.println("The Determinant: "+det);
int trace = (arr[1-1][1-1] + arr[2-1][2-1] + arr[3-1][3-1]);
System.out.println("The Trace: "+trace);
}
}