0% found this document useful (0 votes)
22 views7 pages

Modul 4 Array

This document contains source code for a program that uses multi-dimensional arrays to perform matrix addition, subtraction, and multiplication. The code displays a menu allowing the user to choose an operation. It then prompts the user to enter the number of rows and columns for the matrices. Loops are used to populate the matrices with input values and perform the selected operation, storing the results in a third matrix. The resulting matrices are then displayed.

Uploaded by

lukinanda
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views7 pages

Modul 4 Array

This document contains source code for a program that uses multi-dimensional arrays to perform matrix addition, subtraction, and multiplication. The code displays a menu allowing the user to choose an operation. It then prompts the user to enter the number of rows and columns for the matrices. Loops are used to populate the matrices with input values and perform the selected operation, storing the results in a third matrix. The resulting matrices are then displayed.

Uploaded by

lukinanda
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

MODUL 4 Array

A.

Soal
Buatlah program dengan menggunakan Array MultiDimensi untuk menampilkan Penjumlahan, pengurangan, perkalian Matriks

1.

B. Source Code
public class Array { public static void main (String [] udin){ do{ int menu=Integer.parseInt(JOptionPane.showInputDialog("Matrik \n"+ "1. Penjumlahan\n"+ "2. Pengurangan\n"+ "3. Perkalian\n"+ "4. Keluar" )); switch(menu){ case 1: int bmt1=Integer.parseInt(JOptionPane.showInputDialog("Masukkak baris")); int kmt1=Integer.parseInt(JOptionPane.showInputDialog("Masukkak Kolom")); //int bmt2=Integer.parseInt(JOptionPane.showInputDialog("Masukkak baris")); //int kmt2=Integer.parseInt(JOptionPane.showInputDialog("Masukkak Kolom")); int matrik1[][]=new int [bmt1][kmt1]; int matrik2[][]=new int [bmt1][kmt1]; int matrik3[][]=new int [bmt1][kmt1]; for(int i=0; i<bmt1; i++){ for (int j=0 ;j<kmt1; j++) matrik1[i][j]=Integer.parseInt(JOptionPane.showInputDialog("[matrik1]\n Baris ke-"+i+" Kolom ke-"+j)); } for(int i=0; i<bmt1; i++){ for (int j=0 ;j<kmt1; j++) matrik2[i][j]=Integer.parseInt(JOptionPane.showInputDialog("[matrik2]\n Baris ke-"+i+" Kolom ke-"+j));

} for(int i=0; i<bmt1; i++){ for (int j=0 ;j<kmt1; j++) matrik3[i][j]= matrik1[i][j] + matrik2[i][j]; } System.out.println("Matrik 1"); for(int i=0; i<bmt1; i++){ for (int j=0 ;j<kmt1; j++) System.out.print(" "+matrik1[i][j]); System.out.println(); } System.out.println("Matrik 2"); for(int i=0; i<bmt1; i++){ for (int j=0 ;j<kmt1; j++) System.out.print(" "+matrik2[i][j]); System.out.println(); } System.out.println("Matrik 3"); for(int i=0; i<bmt1; i++){ for (int j=0 ;j<kmt1; j++) System.out.print(" "+matrik3[i][j]); System.out.println(); } break; case 2: int bmt2=Integer.parseInt(JOptionPane.showInputDialog("Masukkak baris")); int kmt2=Integer.parseInt(JOptionPane.showInputDialog("Masukkak Kolom")); int matrik4[][] = new int[bmt2][kmt2]; int matrik5[][]=new int [bmt2][kmt2]; int matrik6[][]=new int [bmt2][kmt2]; for(int i=0; i<bmt2; i++){ for (int j=0 ;j<kmt2; j++) matrik4[i][j]=Integer.parseInt(JOptionPane.showInputDialog("[matrik1]\n Baris ke-"+i+" Kolom ke-"+j)); } for(int i=0; i<bmt2; i++){ for (int j=0 ;j<kmt2; j++) matrik5[i][j]=Integer.parseInt(JOptionPane.showInputDialog("[matrik2]\n Baris ke-"+i+" Kolom ke-"+j)); } for(int i=0; i<bmt2; i++){

for (int j=0 ;j<kmt2; j++) matrik6[i][j]= matrik4[i][j] - matrik5[i][j]; } System.out.println("Matrik 1"); for(int i=0; i<bmt2; i++){ for (int j=0 ;j<kmt2; j++) System.out.print(" "+matrik4[i][j]); System.out.println(); }

System.out.println("Matrik 2"); for(int i=0; i<bmt2; i++){ for (int j=0 ;j<kmt2; j++) System.out.print(" "+matrik5[i][j]); System.out.println(); } System.out.println("Matrik 3"); for(int i=0; i<bmt2; i++){ for (int j=0 ;j<kmt2; j++) System.out.print(" "+matrik6[i][j]); System.out.println(); } break; case 3: int bmt=Integer.parseInt(JOptionPane.showInputDialog("Masukkak baris")); int kmt=Integer.parseInt(JOptionPane.showInputDialog("Masukkak Kolom")); int matrika[][] = new int[bmt][kmt]; int matrikb[][]=new int [bmt][kmt]; int matrikc[][]=new int [bmt][kmt]; for(int i=0; i<bmt; i++){ for (int j=0 ;j<kmt; j++) matrika[i][j]=Integer.parseInt(JOptionPane.showInputDialog("[matrik1]\n Baris ke-"+i+" Kolom ke-"+j)); }

for(int i=0; i<bmt; i++){ for (int j=0 ;j<kmt; j++) matrikb[i][j]=Integer.parseInt(JOptionPane.showInputDialog("[matrik2]\n Baris ke-"+i+" Kolom ke-"+j)); } for(int i=0; i<bmt; i++){ for (int j=0 ;j<kmt; j++){ matrikc[i][j]= 0; for (int k=0;k<bmt;k++){ matrikc[i][j]= matrikc[i][j] + matrika[i][k]* matrikb[k][j]; } } } System.out.println("Matrik 1"); for(int i=0; i<bmt; i++){ for (int j=0 ;j<kmt; j++) System.out.print(" "+matrika[i][j]); System.out.println(); }

System.out.println("Matrik 2"); for(int i=0; i<bmt; i++){ for (int j=0 ;j<kmt; j++) System.out.print(" "+matrikb[i][j]); System.out.println(); } System.out.println("Matrik 3"); for(int i=0; i<bmt; i++){ for (int j=0 ;j<kmt; j++) System.out.print(" "+matrikc[i][j]); System.out.println(); }break; case 4: System.exit(0); default:JOptionPane.showMessageDialog(null,"Tidak ada Dalam Menu"); } }while(true); }

}}

C. Output

Daftar Pustaka
1. 2.

Mastering JavaTM Master Java book www.google.com

You might also like