Skip to content

Instantly share code, notes, and snippets.

@peter279k
Created May 24, 2017 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peter279k/d39d48417288c5bd24d89d70c84ce02e to your computer and use it in GitHub Desktop.
Save peter279k/d39d48417288c5bd24d89d70c84ce02e to your computer and use it in GitHub Desktop.
TQC+ JAVA
public class JPA05 {
final static int ROW = 2;
final static int COL = 3;
public static void main(String args[]) {
int A[][] = {{1,2,3}, {4,5,6}};
int B[][] = {{7,8,9}, {10,11,12}};
int C[][] = new int[ROW][COL];
System.out.printf("陣列A的內容為(3x3):\n");
show(A);
System.out.printf("\n陣列B的內容為(3x3):\n");
show(B);
add(A, B, C);
System.out.printf("\n陣列A+B=C,陣列C的內容為(3x3):\n");
show(C);
}
public static void add(int A[][], int B[][], int C[][]) {
for(int index=0;index<ROW;index++) {
for(int j=0;j<COL;j++) {
C[index][j] = A[index][j] + B[index][j];
}
}
}
public static void show(int arr[][]) {
String str = "";
for(int index=0;index<ROW;index++) {
for(int j=0;j<COL;j++) {
if(arr[index][j] <= 9 && arr[index][j] >= 0) {
str += "0" + arr[index][j] + " ";
} else {
str += arr[index][j] + " ";
}
}
str += "\r\n";
}
System.out.println(str);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment