Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Soal Nomer 2 Matrix
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- package javaapplication6;
- public class Rumus {
- private int M1[][];
- private int M2[][];
- private int Jwb[][];
- public int[][] getM1() {
- return M1;
- }
- public void setM1(int[][] M1) {
- this.M1 = M1;
- M1 = null;
- }
- public int[][] getM2() {
- return M2;
- }
- public void setM2(int[][] M2) {
- this.M2 = M2;
- M2 = null;
- }
- public void sout(String a) {
- System.out.println(a);
- a = null;
- }
- public void sout(int M1[][]) {
- int i, j;
- for (i = 0; i < M1.length; i++) {
- for (j = 0; j < M1[i].length; j++) {
- System.out.print(M1[i][j] + " ");
- }
- System.out.println();
- }
- M1 = null;
- }
- public int[][] getCara() {
- return Jwb;
- }
- public void setCara(int[][] M1, int[][] M2) {
- Jwb = M1;
- int i, j;
- for (i = 0; i < M1.length; i++) {
- for (j = 0; j < M1[i].length; j++) {
- Jwb[i][j] = M2[i][j] + M1[i][j];
- }
- }
- M1 = null;
- }
- public void del() {
- M1 = null;
- M2 = null;
- }
- }
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- import javaapplication6.Rumus;
- public class matrix {
- public static void main(String[] args) {
- Rumus R = new Rumus();
- int[][] M1 = {
- {1, 2},
- {3, 4}};
- int[][] M2 = {
- {2, 4},
- {6, 8}};
- System.out.println("Nilai Matriks A");
- R.setM1(M1);
- R.sout(R.getM1());
- System.out.println("Nilai Matriks B");
- R.setM2(M2);
- R.sout(R.getM2());
- System.out.println("Hasil dari penjumlahan Matriks A dan B : ");
- R.setCara(M1, M2);
- R.sout(R.getCara());
- R.del();
- M1 = null;
- M2 = null;
- R = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment