PROGRAM :
package tugasmatrix;
/**
*
* @author Serly
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class matrixx {
static int[][] matrikA = new int[2][2];
static int[][] matrikB = new int[2][3];
static int[][] matrikHasil = new int[2][3];
static int ukuran;
public static void main(String[] args){
System.out.println("Masukkan Ukuran Matriks Yang Anda Inginkan : ");
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 Dari MatrikA :");
for(int i=0; i<ukuran; i++){
for(int j=0; j<ukuran; j++){
System.out.println("Matrik["+(i+1)+"]["+(j+1)+"]");
matrikA[i][j] = inputData();
}
}
System.out.println("Masukkan Data Dari MatrikB :");
for(int i=0; i<ukuran; i++){
for(int j=0; j<ukuran; j++){
System.out.println("Matrik["+(i+1)+"]["+(j+1)+"]");
matrikB[i][j] = inputData();
}
}
}
private static void KalikanMatrix() {
for(int i=0; i<ukuran; i++){
for(int j=0; j<ukuran; j++){
matrikHasil[i][j] = matrikA[i][j]*matrikB[i][j];
}
}
}
private static void tulisHasil() {
System.out.println("\n\nMatrik Dari Hasil Perkalian");
System.out.println("");
for(int i=0; i<ukuran; i++){
for(int j=0; j<ukuran; j++){
System.out.print(matrikHasil[i][j]+"\t");
}
System.out.println("");
}
}
}
OUTPUT :
wrong kode iki mas
BalasHapus