Contoh Program Array 1D
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package array1d;
import javax.swing.JOptionPane;
/**
*
* @author Nafis
*/
public class Array1D {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int baris=Integer.valueOf(JOptionPane.showInputDialog(null,"Masukkan Jumlah Baris Matrik :"," "));
System.out.print("Array Satu Dimensi\n");
int data[]=new int[baris];
for (int i=0; i<baris; i++ ){
System.out.print("|");
data[i]=Integer.parseInt(JOptionPane.showInputDialog(null,"Nilai Array Baris Ke : "+(i+1)));
System.out.print(" "+i+" || "+data[i]+" ");
System.out.println("|");
}
}
}
Contoh Program Array 2D :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package array2d;
import javax.swing.JOptionPane;
/**
*
* @author Nafis
*/
public class Array2D {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int baris=Integer.valueOf(JOptionPane.showInputDialog(null,"Masukkan Jumlah Baris Matrik :"," "));
int kolom=Integer.valueOf(JOptionPane.showInputDialog(null,"Masukkan Jumlah Kolom Matrik "," "));
System.out.print("Array Dua dimensi\n");
int Matrik[][]=new int[baris][kolom];
for (int i=0; i<baris; i++ ){
System.out.print("|");
for (int j=0; j<kolom;j++ ){
Matrik[i][j]=Integer.parseInt(JOptionPane.showInputDialog(null,"Nilai Matrik Baris Ke : "+(i+1)+ " Kolom Ke : " +(j+1)));
System.out.print(" "+Matrik[i][j]+" ");
}
System.out.println("|");
}
}
}
No comments:
Post a Comment