program penjumlahan matriks 4 dimensi dengan java




public class matrix4dimensi
{
 public static void main(String [] argh)
 {
  int A[][] = {{1,3,2,5},{7,9,5,3},{4,7,8,9},{3,8,7,1}};
  int B[][] = {{11,12,19,32},{45,11,13,10},{9,10,17,25},{8,31,39,91}};
  int C[][];
  int i,j;
  C = new int [4][4];
  System.out.println("Matrix A");
  for (i=0; i<=3;i++)
  {
   for (j=0; j<=3;j++)
   {
   System.out.print(A[i][j]+" ");
   }
  System.out.println();
  } 
  System.out.println("Matrix B");
  for (i=0; i<=3;i++)
  {
   for (j=0; j<=3;j++)
   {
   System.out.print(B[i][j]+" ");
   }
  System.out.println();
  }
  System.out.println("Matrix A + Matrix B = Matrix C");
  for (i=0; i<=3;i++)
  {
   for (j=0; j<=3;j++)
   {
   C[i][j]=A[i][j]+B[i][j];
   System.out.print(C[i][j]+" ");
   }
  System.out.println();
  } 
 }
}



Post a Comment

0 Comments