0% found this document useful (0 votes)
26 views2 pages

Import Java

The document defines a Java program that performs addition and subtraction on 4x4 matrices. It takes user input to populate two 4x4 matrices, MatrixA and MatrixB. It then creates two new matrices: one to store the sum of MatrixA and MatrixB, and one to store the difference. The program outputs the individual matrices and results.

Uploaded by

HarryWaterpass
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

Import Java

The document defines a Java program that performs addition and subtraction on 4x4 matrices. It takes user input to populate two 4x4 matrices, MatrixA and MatrixB. It then creates two new matrices: one to store the sum of MatrixA and MatrixB, and one to store the difference. The program outputs the individual matrices and results.

Uploaded by

HarryWaterpass
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

*; public class PenjumlahanDanPenguranganMatrix { public static void main(String args[]) { //untuk memasukkan data Scanner input = new Scanner(System.in); int i; int j; int[][]matrixA = new int[4][4]; int[][]matrixB = new int[4][4]; int[][]jumlahMatrix = new int[4][4]; int[][]kurangMatrix= new int[4][4]; //input matrix A for(i=1;i<4;i++) { for(j=1;j<4;j++) { System.out.print("Matrix A " + i + "." + j + "= "); matrixA[i][j] =input.nextInt(); } } System.out.println(); // input matrix B for(i=1;i<4;i++) { for(j=1;j<4;j++) { System.out.print("Matrix B " + i + "." + j + "= "); matrixB[i][j] =input.nextInt(); } } //penjumlahan Matrix for(i=1;i<4;i++) { for(j=1;j<4;j++) { jumlahMatrix[i][j] = matrixA[i][j] + matrixB[i][j]; kurangMatrix[i][j] = matrixA[i][j] - matrixB[i][j]; } } //tampil matrix A System.out.println("\nMatrix A\n"); for(i=1;i<4;i++) { for(j=1;j<4;j++) {

System.out.print(" " + matrixA[i][j]); } System.out.println(); } //tampil matrix B System.out.println("\nMatrix B\n"); for(i=1;i<4;i++) { for(j=1;j<4;j++) { System.out.print(" " + matrixB[i][j]); } System.out.println(); } //tampil jumlahMatrix B System.out.println("\nMatrixA + Matrix B\n"); for(i=1;i<4;i++) { for(j=1;j<4;j++) { System.out.print(" " + jumlahMatrix[i][j]); } System.out.println(); } //tampil kurangmatrix System.out.println("\nMatrix A - Matrix B\n"); for(i=1;i<4;i++) { for(j=1;j<4;j++) { System.out.print(" " + kurangMatrix[i][j]); } System.out.println(); }

} }

You might also like