IndoproGMR

M_3 Arr Nomer 2 Matrix

Mar 30th, 2021
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. //Soal Nomer 2 Matrix
  2. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  3. package javaapplication6;
  4.  
  5. public class Rumus {
  6.  
  7.     private int M1[][];
  8.     private int M2[][];
  9.     private int Jwb[][];
  10.  
  11.     public int[][] getM1() {
  12.         return M1;
  13.     }
  14.  
  15.     public void setM1(int[][] M1) {
  16.         this.M1 = M1;
  17.         M1 = null;
  18.     }
  19.  
  20.     public int[][] getM2() {
  21.         return M2;
  22.     }
  23.  
  24.     public void setM2(int[][] M2) {
  25.         this.M2 = M2;
  26.         M2 = null;
  27.     }
  28.  
  29.     public void sout(String a) {
  30.         System.out.println(a);
  31.         a = null;
  32.     }
  33.  
  34.     public void sout(int M1[][]) {
  35.         int i, j;
  36.         for (i = 0; i < M1.length; i++) {
  37.             for (j = 0; j < M1[i].length; j++) {
  38.                 System.out.print(M1[i][j] + " ");
  39.             }
  40.             System.out.println();
  41.         }
  42.         M1 = null;
  43.     }
  44.  
  45.     public int[][] getCara() {
  46.         return Jwb;
  47.     }
  48.  
  49.     public void setCara(int[][] M1, int[][] M2) {
  50.         Jwb = M1;
  51.         int i, j;
  52.         for (i = 0; i < M1.length; i++) {
  53.             for (j = 0; j < M1[i].length; j++) {
  54.                 Jwb[i][j] = M2[i][j] + M1[i][j];
  55.             }
  56.         }
  57.         M1 = null;
  58.     }
  59.  
  60.     public void del() {
  61.         M1 = null;
  62.         M2 = null;
  63.     }
  64. }
  65.  
  66.  
  67. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  68.  
  69.  
  70.  
  71.  
  72.  
  73. import javaapplication6.Rumus;
  74.  
  75. public class matrix {
  76.  
  77.     public static void main(String[] args) {
  78.         Rumus R = new Rumus();
  79.         int[][] M1 = {
  80.             {1, 2},
  81.             {3, 4}};
  82.  
  83.         int[][] M2 = {
  84.             {2, 4},
  85.             {6, 8}};
  86.  
  87.         System.out.println("Nilai Matriks A");
  88.         R.setM1(M1);
  89.         R.sout(R.getM1());
  90.  
  91.         System.out.println("Nilai Matriks B");
  92.         R.setM2(M2);
  93.         R.sout(R.getM2());
  94.  
  95.         System.out.println("Hasil dari penjumlahan Matriks A dan B : ");
  96.         R.setCara(M1, M2);
  97.         R.sout(R.getCara());
  98.  
  99.         R.del();
  100.         M1 = null;
  101.         M2 = null;
  102.         R = null;
  103.     }
  104. }
  105.  
Advertisement
Add Comment
Please, Sign In to add comment