Coding Array Matrix pada Java..

import javax.swing.JOptionPane;

public class array{

    public static void main(String [] args){
                System.out.println("=========================================");
                System.out.println("=========== *ARRAY PADA JAVA* ===========");
                System.out.println("============aliefendy.blogspot.com=============");
                System.out.println("=========================================");

        int bM1 = Integer.parseInt(JOptionPane.showInputDialog("Jumlah baris matrik 1?"));
        int kM1 = Integer.parseInt(JOptionPane.showInputDialog("Jumlah kolom matrik 1?"));
        int bM2 = Integer.parseInt(JOptionPane.showInputDialog("Jumlah baris matrik 2?"));
        int kM2 = Integer.parseInt(JOptionPane.showInputDialog("Jumlah kolom matrik 2?"));
        int matrix1[][] = new int[bM1][kM1];
        int matrix2[][] = new int[bM2][kM2];
        int matrix3[][] = new int[bM2][kM2];
        int matrix4[][] = new int[bM2][kM2];
        int matrix5[][] = new int[bM2][kM2];

        for (int i = 0; i < bM1; i++) {
            for (int j = 0; j < kM1; j++)
                matrix1[i][j]=Integer.parseInt(JOptionPane.showInputDialog("[Matrix1]Baris ke-"+i+" Kolom ke-"+j+" ?"));
        }

        for (int i = 0; i < bM2; i++) {
            for (int j = 0; j < kM2; j++)
                matrix2[i][j]=Integer.parseInt(JOptionPane.showInputDialog("[Matrix2] Baris ke-"+i+" Kolom ke-"+j+" ?"));
        }
        for (int i = 0; i < bM1; i++) {
            for (int j = 0; j < kM2; j++){
                matrix3[i][j]= matrix1[i][j] + matrix2[i][j];
            }
        }
             for (int i = 0; i < bM1; i++) {
            for (int j = 0; j < kM2; j++){
                matrix4[i][j]= matrix1[i][j] - matrix2[i][j];
            }
             }
          for (int i = 0; i < bM1; i++) {
            for (int j = 0; j < kM2; j++){
                matrix5[i][j]= matrix1[i][j] * matrix2[i][j];
            }
        }
        System.out.println("Matrik 1");
        for (int i = 0; i < bM1; i++) {
            for (int j = 0; j < kM2; j++)
                System.out.print(" "+matrix1[i][j]);
            System.out.println();
        }
        System.out.println("Matrik 2");
        for (int i = 0; i < bM1; i++) {
            for (int j = 0; j < kM2; j++)
                System.out.print(" "+matrix2[i][j]);
            System.out.println();
        }
        System.out.println("Hasil Jumlah :");
        for (int i = 0; i < bM2; i++) {
            for (int j = 0; j < kM2; j++)
                System.out.print(" "+matrix3[i][j]);
            System.out.println();
        }
         System.out.println("Hasil Kurang :");
        for (int i = 0; i < bM2; i++) {
            for (int j = 0; j < kM2; j++)
                System.out.print(" "+matrix4[i][j]);
            System.out.println();
    }
          System.out.println("HasiL Kali :");
        for (int i = 0; i < bM2; i++) {
            for (int j = 0; j < kM2; j++)
                System.out.print(" "+matrix5[i][j]);
            System.out.println();
}    }  }

0 comments:

Posting Komentar