Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
18 views

"Masukkan Jumlah Baris: " "Masukan Jumlah Kolom: " "Data Pada Matriks:"

This Java code defines a class that calculates the inverse of a 2x2 matrix. It prompts the user to input the number of rows and columns, then the values of the matrix. It prints the original matrix, calculates its determinant, and performs row operations to calculate the inverse, printing the result. The code takes a 2x2 matrix as input from the user, calculates its determinant, performs row operations to find the inverse, and prints the original and inverse matrices.

Uploaded by

YUSRI1997
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

"Masukkan Jumlah Baris: " "Masukan Jumlah Kolom: " "Data Pada Matriks:"

This Java code defines a class that calculates the inverse of a 2x2 matrix. It prompts the user to input the number of rows and columns, then the values of the matrix. It prints the original matrix, calculates its determinant, and performs row operations to calculate the inverse, printing the result. The code takes a 2x2 matrix as input from the user, calculates its determinant, performs row operations to find the inverse, and prints the original and inverse matrices.

Uploaded by

YUSRI1997
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

Scanner;
public class invers2 {
public static void main(String[] args) {
Scanner in = new Scanner (System.in);
int baris,kolom;
System.out.print("masukkan jumlah baris : ");
baris = in.nextByte();
System.out.print("masukan jumlah kolom : ");
kolom = in.nextInt();
System.out.println("data pada matriks :");
int matriks[][]=new int[baris][kolom];
for (int i=0;i<baris;i++){
for(int j=0;j<kolom;j++){
System.out.print("data pada baris ke- "+i+" kolom ke- "+j+" :
");
matriks [i][j]=in.nextInt();
}
}
System.out.println();
System.out.println("matriks sebelum diInvers");
for (int i=0;i<baris;i++){
for (int j=0;j<kolom;j++){
System.out.print(matriks[i][j]+" ");
}
}
//proses invers
float determinan=(matriks[0][0]*matriks[1][1])-(matriks[1]
[0]*matriks[0][1]);
System.out.println("Determinanya Adalah : "+determinan);
int temp = matriks[0][0];
matriks[0][0]=matriks[1][1];
matriks[1][1]= temp;
matriks[0][1]=matriks[0][1]*-1;
matriks[1][0]=matriks[1][0]*-1;
System.out.println("invers dari matriks tersebut adalah : ");
for (int i=0;i<2;i++){
System.out.print("|");
for (int j=0;j<2;j++)
{
System.out.print(matriks[i][j]/determinan+"
");
}
System.out.println("|");
}
}
}

You might also like