Program Perkalian Metrik dengan Java


Mumpung ada kesempatan buat posting, aku pengen posting deh hasil karya saya tentang program perkalian metrik dengan java, Berikut codingnya

import java.util.Scanner;

/**
 *
 * @author rich
 */
public class Metrik {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int a[][] = new int[3][3];
        int b[][] = new int[3][3];
        int hasil[][] = new int[3][3];

        Scanner tampung=new Scanner(System.in);
        for(int putarcol=0;putarcol<a[0].length;putarcol++){
            for(int putarrow=0;putarrow<a[0].length;putarrow++){
                System.out.print("Masukan nilai array A"+putarcol+"."+putarrow+": ");
                int nilai=tampung.nextInt();
                a[putarcol][putarrow]=nilai;

            }
        }
        System.out.println("");
        for(int putarcolom=0;putarcolom<b[0].length;putarcolom++){
            for(int putarbaris=0;putarbaris<b[0].length;putarbaris++){
                System.out.print("Masukan nilai array B"+putarcolom+"."+putarbaris+": ");
                int nilai=tampung.nextInt();
                b[putarcolom][putarbaris]=nilai;

            }
        }
        for (int colom = 0; colom < a[0].length; colom++) {
            for (int row = 0; row < b[0].length; row++) {
                hasil[colom][row] = (a[colom][0] * b[0][row]) + (a[colom][1] * b[1][row]) + (a[colom][2] * b[2][row]);
            }
        }

        for (int o = 0; o < a[0].length; o++) {
            System.out.print("| ");
            for (int p = 0; p < a[0].length; p++) {
                System.out.print(a[o][p] + " ");

            }
            System.out.print("|");
            if (o == 1) {
                System.out.print("X");
            }else{
                System.out.print(" ");}
            System.out.print("| ");
            for (int q = 0; q < b[0].length; q++) {
                System.out.print(b[o][q]+" ");

            }
            System.out.print("|");
            if (o == 1) {
                System.out.print("=");
            }else{
                System.out.print(" ");}
            System.out.print("| ");
            for (int r = 0; r < hasil[0].length; r++) {
                System.out.print(+hasil[o][r] + " ");
            }
            System.out.print("|");
            System.out.println(" ");
        }

    }

}

Berikut programnya  download

5 pemikiran pada “Program Perkalian Metrik dengan Java

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s