Selasa, 12 April 2011

Program Membuat matriks dengan java


Membuat matriks
import javax.swing.*;
class  matriks
{
                public static void main(String[] args)
                {
                                int ordo=Integer.parseInt(JOptionPane.showInputDialog("Masukan Ordo Matriks"));
                                int [][] ma=new int [ordo][ordo];
                                int [][] mb=new int [ordo][ordo];
                                int [][] kali=new int [ordo][ordo];
                                int i,j,k,temp;
                                for (i=0;i
                                {
                                                for (j=0;j
                                                {
                                                                String n=JOptionPane.showInputDialog("Matriks A elemen ke {"+(i+1)+","+(j+1)+"}");
                                                                ma[i][j]=Integer.parseInt(n);
                                                }
                                }
                                for (i=0;i
                                {
                                                for (j=0;j
                                                {
                                                                String m=JOptionPane.showInputDialog("Matriks B elemen ke {"+(i+1)+","+(j+1)+"}");
                                                                mb[i][j]=Integer.parseInt(m);
                                                }
                                }
                                System.out.println("Matriks A");
                                for (i=0;i
                                {
                                                for (j=0;j
                                                {
                                                                System.out.print(ma[i][j]+" ");
                                                }
                                                System.out.println("\n");
                                }
                                System.out.println("Matriks B");
                                for (i=0;i
                                {
                                                for (j=0;j
                                                {
                                                                System.out.print(mb[i][j]+" ");
                                                }
                                                System.out.println("\n");
                                }
                                for (i=0;i
                                {
                                                for (j=0;j
                                                {
                                                                temp =0;
                                                                for (k=0;k
                                                                {
                                                                                temp=temp+(ma[i][k]*mb[k][j]);
                                                                }
                                                                kali[i][j]=temp;
                                                }
                                }
                                System.out.println("hasil perkalian matriks A dan B");
                                for (i=0;i
                                {
                                                for (j=0;j
                                                {
                                                                System.out.print(kali[i][j]+" ");
                                                }
                                                System.out.println("\n");
                                }
                }
}

Tidak ada komentar:

Posting Komentar