-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayOps.java
58 lines (52 loc) · 1.39 KB
/
ArrayOps.java
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
/**
* @(#)ArrayOps.java
*
*
* @author
* @version 1.00 2016/11/28
*/
public abstract class ArrayOps {
public ArrayOps() {
}
public static int[][] copyArr8(int[][] arrIn){
int[][] arrOut= new int[arrIn.length][arrIn[0].length];
for(int i=0; i<8; i++){
for (int j=0; j<8; j++){
arrOut[i][j]=arrIn[i][j];
}
}
return arrOut;
// The algo below /should/ be faster, but it isn't. Approx 2x slower.
// for (int i = 0; i < arrIn.length; i++) {
// System.arraycopy(arrIn[i], 0, arrOut[i], 0, arrIn[0].length);
// }
}
public static int[][] addArrayElements(int[][] foo, int[][] bar){
for(int i=0; i<8; i++){
for(int j=0; j<8; j++){
foo[i][j]=foo[i][j]+bar[i][j];
}
}
return foo;
}
public static void print8x8(int[][] PARAMETER_ARRAY){
System.out.println();
for(int r=0; r<8; r++){
for(int c=0; c<8; c++){
if(PARAMETER_ARRAY[r][c]==0){
System.out.print("0");
}
System.out.print(PARAMETER_ARRAY[r][c]+",");
}
System.out.println();
}
}
public static int[][] multiplyArrayElements(int[][] foo, int[][] bar){
for(int i=0; i<8; i++){
for(int j=0; j<8; j++){
foo[i][j]=foo[i][j]*bar[i][j];
}
}
return foo;
}
}