Kamis, 10 November 2011

Operasi array matriks

import javax.swing.JOptionPane;

/**
 *
 * @author Zed
 */
public class Operasi_Matriks {
    public static void main(String[] args) {

        System.out.println("Operasi Matriks");
        int row = Integer.parseInt(JOptionPane.showInputDialog(null,"Masukkan Jumlah Baris: "));
        int col = Integer.parseInt(JOptionPane.showInputDialog(null,"Masukkan Jumlah Kolom: "));
        double A[][] = new double[row][col];
        double B[][] = new double[row][col];
        double C[][] = new double[row][col];
        double D[][] = new double[row][col];
        int i,j,k;

        System.out.println("\nMatriks A");
        for(i=0;i
            System.out.print("| ");
            for(j=0;j
                A[i][j] = Double.parseDouble(JOptionPane.showInputDialog(null,"Masukkan Matriks A ["+(i+1)+","+(j+1)+"]"));
                System.out.print(" "+A[i][j]+" ");
            }
            System.out.println(" |");
        }

        System.out.println("\nMatriks B");
        for(i=0;i
            System.out.print("| ");
            for(j=0;j
                B[i][j] = Double.parseDouble(JOptionPane.showInputDialog(null,"Masukkan Matriks B ["+(i+1)+","+(j+1)+"]"));
                System.out.print(" "+B[i][j]+" ");
            }
            System.out.println(" |");
        }

        System.out.println("\nPenjumlahan Matriks");
        System.out.println("Matriks A + B =");
        for(i=0;i
            System.out.print(" | ");
            for(j=0;j
                for(k=0;k
                C[i][j] = (A[i][j]+B[i][j]);
                }
            System.out.print(" "+C[i][j]+" ");
            }
            System.out.println(" | ");
        }

        System.out.println("\nPengurangan Matriks");
        System.out.println("Matriks A - B =");
        for(i=0;i
            System.out.print(" | ");
            for(j=0;j
                for(k=0;k
                C[i][j] = (A[i][j]-B[i][j]);
                }
            System.out.print(" "+C[i][j]+" ");
            }
            System.out.println(" | ");
        }

        System.out.println("\nPerkalian Matriks");
        System.out.println("Matriks A x B =");
        for(i=0;i
            System.out.print(" | ");
            for(j=0;j
                for(k=0;k
                D[i][j] = D[i][j]+(A[i][k] * B[k][j]);
                }
            System.out.print(" "+D[i][j]+" ");
            }
            System.out.println(" | ");
        }

    }
}

Kamis, 03 November 2011

looping tugaz

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package igara;

/**
 *
 * @author ASUS
 */
public class looptugas {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

         for(int a=1; a<=5; a++){
            for (int b=1; b<=a; b++)
                System.out.print(b);
                System.out.print("\n") ;
        // TODO code application logic here
    }
    }
}

looping

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package igarah;

/**
 *
 * @author ASUS
 */
public class looping {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

         for(int k=1; k<=4; k++){
            for (int j=1; j<=k; j++)
                System.out.print(k);
                System.out.print("\n");
        // TODO code application logic here
    }

    }
}