/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package TUGAS_2; /** * * @author MOHAMAD RAMLI * NIM 1310651201 */ public class matriks_penjumlahan { public static void main(String[] args) { int a [][]= {{3,2},{4,5}}; int b [][]= {{5,4},{6,8}}; int penjumlahan [][]= new int [2][2]; System.out.println("Matriks A"); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { System.out.print(a[i][j]+" "); } System.out.println(""); } System.out.println("Matriks B"); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { System.out.print(b[i][j]+" "); } System.out.println(""); } System.out.println("Hasil penjumlahan"); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { penjumlahan [i][j]= a[i][j]+b[i][j]; System.out.print(penjumlahan[i][j]+" "); } System.out.println(""); } } }
outputnya penjumlahan :
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package TUGAS_2; /** * * @author MOHAMMAD RAMLI * NIM 1310651201 */ public class matriks_pengurangan { public static void main(String[] args) { int [][]a ={{3,4},{5,6}}; int [][]b ={{2,1},{4,3}}; int pengurangan [][] = new int [2][2]; System.out.println("Matriks A"); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { System.out.print(a[i][j]+" "); } System.out.println(" "); } System.out.println("Matriks B"); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { System.out.print(b[i][j]+" "); } System.out.println(" "); } System.out.println("hasil pengurangan"); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { System.out.print(a[i][j]-b[i][j]+ " "); } System.out.println(" "); } } }outputnya :
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package TUGAS_2; /** * * @author MOHAMMAD RAMLI * NIM 1310651201 */ public class matriks_perkaliaan { public static void main(String[] args) { int a[][]={{1,2},{3,4}}; int b[][]={{5,6},{7,8}}; int perkalian [][] = new int [2][2]; System.out.println("Matriks A"); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { System.out.print(a[i][j]+" "); } System.out.println(""); } System.out.println("Matriks B"); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { System.out.print(b[i][j]+" "); } System.out.println(""); } System.out.println("Hasil perkalian"); int satu =(a[0][0]*b[0][0] + a[0][1]*b[1][0]); int dua =(a[0][0]*b[0][1] + a[0][1]*b[1][1]); int tiga =(a[1][0]*b[0][0] + a[1][1]*b[1][0]); int empat =(a[1][0]*b[0][1] + a[1][1]*b[1][1]); System.out.print(satu+" "+dua+" "); System.out.println(""); System.out.print(+tiga+" "+empat+" "); } }outputnya :
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package matriks; /** * * @author MOHAMMAD RAMLI * NIM 1310651201 */ public class pembagian { public static void main(String[] args) { int a [][]= {{10,8},{4,6}}; int b [][]= {{2,4},{8,4}}; int pembagian [][]= new int [2][2]; System.out.println("Matriks A"); for (int i = 0; i < pembagian.length; i++) { for (int j = 0; j < pembagian.length; j++) { System.out.print(a[i][j]+" "); } System.out.println(""); } System.out.println("Matriks B"); for (int i = 0; i < pembagian.length; i++) { for (int j = 0; j < pembagian.length; j++) { System.out.print(b[i][j]+" "); } System.out.println(""); } System.out.println("hasil pembagian :"); for (int i = 0; i < pembagian.length; i++) { for (int j = 0; j < pembagian.length; j++) { for (int k = 0; k < pembagian.length; k++) { pembagian [i][j]-= a[i][k]/ b[j][k]; } System.out.print(pembagian[i][j]+" "); } System.out.println(""); } } }outpunya :
sekian dari artikel saya, apabila ada kesalahan saya mohon maaf, jangan lupa untuk memberi komentar, dan semoga bermanfaat.
0 Komentar Sahabat:
Post a Comment
Jadilah yang pertama...