program matrik pada java ...disni menggunakan java swing
copy script di bawah ini
import javax.swing.*;
class matrixs
{
public static void main(String[] args)
{
System.out.print("matriks A\n");
int baris=Integer.parseInt(JOptionPane.showInputDialog(null,"masukan banyak baris untuk matrix : ","2"));
int kolom=Integer.parseInt(JOptionPane.showInputDialog(null,"masukan banyak kolom untuk matrix : ","2"));
int a[][]=new int[baris][kolom];
for (int i=0; i<baris;i++ )
{
System.out.print("|");
for (int j=0; j<kolom;j++ )
{
a[i][j]=Integer.parseInt(JOptionPane.showInputDialog(null,"nilai A baris ke - "+(i+1) + " kolom ke - " +(j+1)+" : ","0"));
System.out.print(" "+a[i][j]+" ");
}
System.out.print("|");
System.out.print("\n");
}
System.out.println("");
System.out.print("matriks B\n");
int b[][]=new int[baris][kolom];
for (int i=0; i<baris;i++ )
{
System.out.print("|");
for (int j=0; j<kolom;j++ )
{
b[i][j]=Integer.parseInt(JOptionPane.showInputDialog(null,"nilai B baris ke - "+(i+1) + " kolom ke - " +(j+1)+" : ","0"));
System.out.print(" "+b[i][j]+" ");
}
System.out.print("|");
System.out.print("\n");
}
System.out.println("");
System.out.print("OPERASI PENJUMLAHAN MATRIX");
System.out.println("");
for (int i=0; i<baris;i++ )
{
System.out.print(" | ");
for (int j=0; j<kolom;j++ )
{
System.out.print(" "+(a[i][j]+b[i][j])+" ");
}
System.out.print(" | ");
System.out.print("\n");
}
System.out.println("");
System.out.print("OPERASI PENGURANGAN MATRIX");
System.out.println("");
for (int i=0; i<baris;i++ )
{
System.out.print(" | ");
for (int j=0; j<kolom;j++ )
{
System.out.print(" "+(a[i][j]-b[i][j])+" ");
}
System.out.print(" | ");
System.out.print("\n");
}
}
}
simpan harus sama dengan nama " class nya " jangan lupa di compiler.. atau di compile.. selamat mencoba.. semoga bermanfaat ^_^
No comments:
Post a Comment
Udah di baca kan.... kritik dan sarannya saya persilahkan ^_^..jangan lupa isi Buku tamunya juga ya...