返回列表 發帖
  1. public class JPA05 {
  2.     final static int ROW = 2;
  3.     final static int COL = 3;

  4.     public static void main(String args[]) {
  5.         int A[][] = {{1,2,3}, {4,5,6}};
  6.         int B[][] = {{7,8,9}, {10,11,12}};
  7.         int C[][] = new int[ROW][COL];
  8.       
  9.         System.out.printf("陣列A的內容為(3x3):\n");   
  10.         show(A);
  11.       
  12.         System.out.printf("\n陣列B的內容為(3x3):\n");   
  13.         show(B);
  14.       
  15.         add(A, B, C);
  16.       
  17.         System.out.printf("\n陣列A+B=C,陣列C的內容為(3x3):\n");   
  18.         show(C);
  19.     }
  20.    
  21.     public static void add(int a[][] , int b[][] , int c[][]) {
  22.             for(int i=0 ; i<ROW ; i++)
  23.             {
  24.                     for(int j=0; j<COL ; j++)
  25.                     {
  26.                             c[i][j]=a[i][j]=b[i][j];                 
  27.             }
  28.             }
  29.     }
  30.    
  31.     public static void show(int temp[][]) {
  32.             for(int i=0 ; i<ROW ; i++)
  33.             {
  34.                     for(int j=0; j<COL ; j++)
  35.                     {
  36.             System.out.println (temp[i][j]);
  37.     }
  38.     System.out.println("");
  39. }
  40. }
  41. }
複製代碼

TOP

返回列表