Just sharing the code for all,
You can copy an existing program code below
import java.io.*;
class menudeterminan
{
public static void main(String[] args)throws Exception
{
DataInputStream data = new DataInputStream (System.in);
System.out.println ("\n===================================");
System.out.println ("||Mencari Determinan dari Matriks||");
System.out.println ("===================================");
System.out.println ("|| 1. Matriks 2x2 ||");
System.out.println ("|| 2. Matriks 3x3 ||");
System.out.println ("===================================\n");
System.out.print ("Masukkan pilihan anda : ");
int pil = Integer.parseInt(data.readLine());
if (pil==1)
{
System.out.println ("\nAnda Memilih Untuk Mencari Determinan 2x2");
System.out.println ("\n===================================");
System.out.println ("Mencari Determinan dari Matriks 2x2");
System.out.println ("===================================\n");
System.out.println ("Masukkan Data anggota Matriks 2x2 : ");
int n = 2;
int Matriks[][]=new int [n][n];
for (int i=0;i<n ;i++ )
{
for (int j=0;j<n ;j++ )
{
System.out.print("posisi ("+(i+1)+","+(j+1)+") adalah : ");
Matriks[i][j]=Integer.parseInt(data.readLine());
}
}
System.out.println ("\n");
int a = Matriks[0][0];
int b = Matriks[0][1];
int c = Matriks[1][0];
int d = Matriks[1][1];
System.out.println ("Maka Bentuk Matriksnya adalah sebagai berikut : \n");
System.out.println ("( "+a+" "+b+" )");
System.out.println ("( "+c+" "+d+" )\n");
System.out.print ("Maka Determinan dari Matriks nya adalah : "+((a*d)-(b*c))+"\n");
}
else if (pil==2)
{
System.out.println ("\nAnda Memilih Untuk Mencari Determinan 3x3");
System.out.println ("\n===================================");
System.out.println ("Mencari Determinan dari Matriks 3x3");
System.out.println ("===================================\n");
System.out.println ("Masukkan Data anggota Matriks 3x3 : ");
int n = 3;
int Matriks[][]=new int [n][n];
for (int i=0;i<n ;i++ )
{
for (int j=0;j<n ;j++ )
{
System.out.print("posisi ("+(i+1)+","+(j+1)+") adalah : ");
Matriks[i][j]=Integer.parseInt(data.readLine());
}
}
System.out.println ("\n");
int a = Matriks[0][0];
int b = Matriks[0][1];
int c = Matriks[0][2];
int d = Matriks[1][0];
int e = Matriks[1][1];
int f = Matriks[1][2];
int g = Matriks[2][0];
int h = Matriks[2][1];
int i = Matriks[2][2];
System.out.println ("Maka Bentuk Matriksnya adalah sebagai berikut : \n");
System.out.println ("( "+a+" "+b+" "+c+" )");
System.out.println ("( "+d+" "+e+" "+f+" )");
System.out.println ("( "+g+" "+h+" "+i+" )\n");
System.out.print ("Maka Determinan dari Matriks nya adalah : "+((a*e*i)+(b*f*g)+(c*d*h)-(c*e*g)-(a*f*h)-(b*d*i))+"\n");
}
else
System.out.println ("\nMaaf Tidak Ada Pilihan "+pil+" Dalam Menu\n");
}
}
Tidak ada komentar:
Posting Komentar