MENGHITUNG
MATRIKS DALAM JAVA
Berikut koding dalam bahasa java
import java.io.IOException;
import java.io.InputStreamReader;
public class matrix {
static int[][] matrixA = new int[2][2];
static int[][] matrixB = new int[2][3];
static int[][] matrixHasil = new int[2][3];
static int ukuran;
public static void main(String[] args){
System.out.println("Masukkan ukuran matrix : ");
ukuran = inputData();
bacaMatrix();
KalikanMatrix();
tulisHasil();
}
private static int inputData() {
BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
String angkaInput = null;
try{
angkaInput = bfr.readLine();
}
catch(IOException e){
e.printStackTrace();
}
int Data=Integer.valueOf(angkaInput).intValue();
return Data;
}
private static void bacaMatrix() {
System.out.println("Masukkan data MatrixA :");
for(int i=0; i<ukuran; i++){
for(int j=0; j<ukuran; j++){
System.out.println("Matrix["+(i+1)+"]["+(j+1)+"]");
matrixA[i][j] = inputData();
}
}
System.out.println("Masukkan data MatrixB :");
for(int i=0; i<ukuran; i++){
for(int j=0; j<ukuran; j++){
System.out.println("Matrix["+(i+1)+"]["+(j+1)+"]");
matrixB[i][j] = inputData();
}
}
}
private static void KalikanMatrix() {
for(int i=0; i<ukuran; i++){
for(int j=0; j<ukuran; j++){
matrixHasil[i][j] = matrixA[i][j]*matrixB[i][j];
}
}
}
private static void tulisHasil() {
System.out.println("\n\nMatrix Hasil Perkalian");
System.out.println("");
for(int i=0; i<ukuran; i++){
for(int j=0; j<ukuran; j++){
System.out.print(matrixHasil[i][j]+"\t");
}
System.out.println("");
}
}
}
INILAH HASILX.....