Perkalian Matriks dengan JAVA

package lapresS3; import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner input = new Scanner(System.in); int[][] matriksA = new int[2][3]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { System.out.printf("Masukkan MatriksA baris %d kolom %d : ", (i+1), (j+1)); matriksA[i][j] = input.nextInt(); } } System.out.println(); for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { System.out.print(matriksA[i][j] + " "); }System.out.println(); } int[][] matriksB = new int[3][2]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { System.out.printf("Masukkan MatriksB baris %d kolom %d : ", (i+1), (j+1)); matriksB[i][j] = input.nextInt(); } } System.out.println(); for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { System.out.print(matriksB[i][j] + " "); }System.out.println(); } int[][] hasil = new int[2][2]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { int x = 0; for (int k = 0; k < 3; k++) { x += matriksA[i][k]*matriksB[k][j]; } hasil[i][j] = x; } } for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { System.out.print(hasil[i][j] + " "); }System.out.println(); } } }
Tinggal ubah nama package sama classnya,
langsung run aja

1 Response

boleh kasih contoh hasilnya kak

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.