import javax.swing.*;
public class matriks3
{
public static void main (String [] args)
{
int ordo = 3;
int A[][] = new int [ordo][ordo];
int B[][] = new int [ordo][ordo];
int C[][] = new int [ordo][ordo];
for (int baris=0; baris<ordo; baris++)
{
for (int kolom=0; kolom<ordo; kolom++ )
{
A[baris][kolom] = Integer.parseInt(JOptionPane.showInputDialog("Masukkan Matriks A ["+(baris)+"]["+(kolom)+"]"));
B[baris][kolom] = Integer.parseInt(JOptionPane.showInputDialog("Masukkan Matriks B ["+(baris)+"]["+(kolom)+"]"));
C[baris][kolom] = Integer.parseInt(JOptionPane.showInputDialog("Masukkan Matriks C ["+(baris)+"]["+(kolom)+"]"));
}
}
System.out.println("\n"+"Matriks A");
for (int baris=0; baris<ordo ;baris++ )
{
for (int kolom=0;kolom<ordo ;kolom++ )
{
System.out.print ("| "+A[baris][kolom]+" ");
}
System.out.println ("| ");
}
System.out.println("\n"+"Matriks B");
for (int baris=0 ;baris<ordo ;baris++ )
{
for (int kolom=0; kolom<ordo; kolom++ )
{
System.out.print ("| "+B[baris][kolom]+" ");
}
System.out.println ("| ");
}
System.out.println("\n"+"Matriks C");
for (int baris=0 ;baris<ordo ;baris++ )
{
for (int kolom=0; kolom<ordo; kolom++ )
{
System.out.print ("| "+C[baris][kolom]+" ");
}
System.out.println ("| ");
}
}}
Selasa, 19 Agustus 2014
contoh program array dalam Java
class array5 {
public static void main(String args[]){
// Langkah 1: deklarasi variabel array dan penciptaan
int int2DUnequalArr[][] = new int[4][];
int2DUnequalArr[0] = new int[1];
int2DUnequalArr[1] = new int[2];
int2DUnequalArr[2] = new int[3];
int2DUnequalArr[3] = new int[4];
int k=0;
for (int i=0;i<4;i++) {
for (int j=0;j<i+1;j++){
int2DUnequalArr [i][j] = k++;
}
}
for (int i=0;i<4;i++) {
for (int j=0;j<i+1;j++){
System.out.print(int2DUnequalArr[i][j] + " ");
}
System.out.println();
}
}
}
public static void main(String args[]){
// Langkah 1: deklarasi variabel array dan penciptaan
int int2DUnequalArr[][] = new int[4][];
int2DUnequalArr[0] = new int[1];
int2DUnequalArr[1] = new int[2];
int2DUnequalArr[2] = new int[3];
int2DUnequalArr[3] = new int[4];
int k=0;
for (int i=0;i<4;i++) {
for (int j=0;j<i+1;j++){
int2DUnequalArr [i][j] = k++;
}
}
for (int i=0;i<4;i++) {
for (int j=0;j<i+1;j++){
System.out.print(int2DUnequalArr[i][j] + " ");
}
System.out.println();
}
}
}
Langganan:
Postingan (Atom)