Selasa, 12 April 2011

Membuat determinan dengan bahasa JAVA


Berikut codenya, semoga bermanfaat


import java.io.*;
class determinan
{
               
                public static void main (String[] args) throws Exception
                {
                                BufferedReader input =( new InputStreamReader (System.in));
                               
                                System.out.print("ordo matriks = 2*2");
                int [][] matrik = new int [2][2];
                               
                                System.out.println("masukan elemen matriksnya:");
                                for(int i=0;i<2;i++)
                                {
                                                for(int j=0;j<2;j++)
                                                {
                                                  System.out.print("elemen ["+(i+1)+","+(j+1)+"]=");
                                                  matrika[i][j]=Integer.parseInt(input.readLine());
                                                 
                                                 }
                                }
                               
                                for(int i=0;i<2;i++)
                                {
                                                System.out.print("|");
                                                for(int j=0;j<2;j++)
                                                {
                                                                System.out.print(matrika[i][i]+" ");
                                                               
                                               
                                                 System.out.println("|");
                                }
                                int dtr=(matrika[1][0]*matrika[1][1])-(matrika[1][0]*matrika[0][1]);
                                System.out.println("determinnya="+i);
                               
                               
}
}
}

Tidak ada komentar:

Posting Komentar