MATRIKS 3 X 3

package Matriks; import java.util.*; class Matriks{ int baris,kolom,k; int[][] Matriks=new int[3][3]; static Scanner save=new Scanner(System.in); void input(){ for(baris=0;baris<3;baris++){ for(kolom=0;kolom<3;kolom++){ System.out.printf("[%d][%d] =",baris+1,kolom+1); Matriks[baris][kolom]=save.nextInt(); } } } void tampil(){ for(baris=0;baris<3;baris++){ for(kolom=0;kolom<3;kolom++){ System.out.print(Matriks[baris][kolom]+" "); } System.out.println(); } } public static void main(String[] args) { int menu=0,i=0,hapus,x; Matriks[] matriks=new Matriks[2048]; Matriks[] matriks2=new Matriks[2048]; Kali[] matriks3=new Kali[2048]; while(menu!=4){ System.out.print("\n1.input\n2.view\n3.delete\n4.exit\npilih menu = "); menu=save.nextInt(); switch(menu){ case 1 :i++; System.out.println("MATRIKS A"); matriks[i]=new Matriks(); matriks[i].input(); System.out.println("MATRIKS B"); matriks2[i]=new Matriks(); matriks2[i].input(); matriks3[i]=new Kali(matriks[i],matriks2[i]); break; case 2 : if(i==0){ System.out.println("data kosong"); } else{ for(x=1;x<=i;x++){ System.out.printf("\nDATA ke %d\n",x); System.out.println("matriks a"); matriks[x].tampil(); System.out.println("matriks b"); matriks2[x].tampil(); System.out.println("hasil"); matriks3[x].tampil(); } } break; case 3 : if(i==0){ System.out.println("data kosong"); } else{ System.out.print("data ke berapa yang akan di delete = "); hapus=save.nextInt(); if(hapus>0 && hapus<=i){ for(x=hapus;x<=i;x++){ matriks[x]=matriks[x+1]; } System.out.println("DATA BERHASIL DIHAPUS"); i--; } else System.out.println(" data tidak ditemukan"); } break; case 4 :System.out.println("exit. . ."); menu=4; break; default : System.out.println(" pilih menu yang ada"); break; } } } } class Kali extends Matriks{ public Kali(Matriks a,Matriks b){ for(baris=0;baris<3;baris++){ for(kolom=0;kolom<3;kolom++){ Matriks[baris][kolom]=0; for(k=0;k<3;k++){ Matriks[baris][kolom]+=(a.Matriks[baris][k]*b.Matriks[k][kolom]); } } } } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.