Efek

Senin, 07 Maret 2011

Tugas PBO ( matriks )

import java.io.*;
public class pbo1
{
public static void main (String [] args ) throws IOException
{
BufferedReader input = new BufferedReader ( new InputStreamReader (System.in));
System.out.println ("Matriks Ordo 3 x 3 \n");
int [][] matriks1 = new int [3][3];
int [][] matriks2 = new int [3][3];
int [][] matriks3 = new int [3][3];

// elemen matriks pertama
System.out.println ("Masukan banyaknya elemen matriks A !" );
for (int i=0;i<3;i++)
{
for (int j=0;j<3;j++)
{
System.out.print ("Elemen [" +(i+1)+ "," +(j+1)+ "] :");
matriks1[i][j] = Integer.parseInt(input.readLine());
}
}

// elemen matriks kedua
System.out.print("\n");
System.out.println ("Masukan banyaknya elemen matriks B !" );
for (int i=0;i<3;i++)
{
for (int j=0;j<3;j++)
{
System.out.print ("Elemen [" +(i+1)+ "," +(j+1)+ "] :");
matriks2[i][j] = Integer.parseInt(input.readLine());
}
}

// cetak elemen matriks pertama
System.out.print("\n");
for (int i=0;i<3;i++)
{
for (int j=0;j<3;j++)
{
System.out.print(matriks1[i][j]+" ");
}
System.out.println();
}


// cetak elemen matriks kedua
System.out.print("\n");
for (int i=0;i<3;i++)
{
for (int j=0;j<3;j++)
{
System.out.print(matriks2[i][j]+" ");
}
System.out.println();
}

//perkalian matriks
System.out.print("\n");
System.out.println("Perkalian MATRIKS A dan B ");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
{
matriks3[i][j] = matriks3[i][j] + (matriks1[i][j] * matriks2[j][i]);
}
System.out.print(matriks3[i][j]+" ");
}
System.out.println();
}

}
}

Tidak ada komentar:

Posting Komentar