Mumpung ada kesempatan buat posting,saya (Robie) pengen posting deh hasil karya saya tentang program perkalian metrik dengan java, Berikut codingnya
Berikut programnya download
01 | import java.util.Scanner; |
02 |
03 | /** |
04 | * |
05 | * @author rich |
06 | */ |
07 | public class Metrik { |
08 |
09 | /** |
10 | * @param args the command line arguments |
11 | */ |
12 | public static void main(String[] args) { |
13 | int a[][] = new int[3][3]; |
14 | int b[][] = new int[3][3]; |
15 | int hasil[][] = new int[3][3]; |
16 |
17 | Scanner tampung=new Scanner(System.in); |
18 | for(int putarcol=0;putarcol<a[0].length;putarcol++){ |
19 | for(int putarrow=0;putarrow<a[0].length;putarrow++){ |
20 | System.out.print("Masukan nilai array A"+putarcol+"."+putarrow+": "); |
21 | int nilai=tampung.nextInt(); |
22 | a[putarcol][putarrow]=nilai; |
23 |
24 | } |
25 | } |
26 | System.out.println(""); |
27 | for(int putarcolom=0;putarcolom<b[0].length;putarcolom++){ |
28 | for(int putarbaris=0;putarbaris<b[0].length;putarbaris++){ |
29 | System.out.print("Masukan nilai array B"+putarcolom+"."+putarbaris+": "); |
30 | int nilai=tampung.nextInt(); |
31 | b[putarcolom][putarbaris]=nilai; |
32 |
33 | } |
34 | } |
35 | for (int colom = 0; colom < a[0].length; colom++) { |
36 | for (int row = 0; row < b[0].length; row++) { |
37 | hasil[colom][row] = (a[colom][0] * b[0][row]) + (a[colom][1] * b[1][row]) + (a[colom][2] * b[2][row]); |
38 | } |
39 | } |
40 |
41 | for (int o = 0; o < a[0].length; o++) { |
42 | System.out.print("| "); |
43 | for (int p = 0; p < a[0].length; p++) { |
44 | System.out.print(a[o][p] + " "); |
45 |
46 | } |
47 | System.out.print("|"); |
48 | if (o == 1) { |
49 | System.out.print("X"); |
50 | }else{ |
51 | System.out.print(" ");} |
52 | System.out.print("| "); |
53 | for (int q = 0; q < b[0].length; q++) { |
54 | System.out.print(b[o][q]+" "); |
55 |
56 | } |
57 | System.out.print("|"); |
58 | if (o == 1) { |
59 | System.out.print("="); |
60 | }else{ |
61 | System.out.print(" ");} |
62 | System.out.print("| "); |
63 | for (int r = 0; r < hasil[0].length; r++) { |
64 | System.out.print(+hasil[o][r] + " "); |
65 | } |
66 | System.out.print("|"); |
67 | System.out.println(" "); |
68 | } |
69 |
70 | } |
71 |
72 | } |
Tidak ada komentar:
Posting Komentar
Masukan Komentar anda Pada Kotak di Bawah Ini tentaNg Blog Robie