array 2 dmensi

Posted on 4:40 AM by Rudi Syaifudin

lagi buka2 arsip nh, mumpung lg ada contoh program java, yah gw upload aj.



import com.sun.org.apache.bcel.internal.generic.GOTO;
import java.util.Scanner;

public class animal {
public static void main(String[] args) {
String data[][]={{"Gajah","Abu-abu","Rumput"},
{"Merpati","Putih","Biji"},
{"Macan","Kuning","Daging"},
{"Kodok","Hijau","Lumut"}};

Scanner input =new Scanner(System.in);
int x;
System.out.println("###DAFTAR PILIHAN YANG TERSEDIA ###");
System.out.println(" 1. Tampilkan semua elemen.");
System.out.println(" 2. Tampilkan semua data kolom.");
System.out.println(" 3. Tampilkan semua data baris.");
System.out.println(" 4. Tampilkan : Gajah Putih Abu-abu Pemakan Daging dan rumput.");


do{
System.out.print("\n Masukan Pilihan: ");
x=input.nextInt();
switch(x){
case 1:
System.out.println("\n Tampilkan semua elemen.\n");
try{
int i;
for(i=0;i<=data.length;i++){ System.out.print(" "+data[i][0]); System.out.print(" "+data[i][1]); System.out.print(" "+data[i][2]); System.out.println(""); } } catch(ArrayIndexOutOfBoundsException ae){ } break; case 2: System.out.println("\n Tampilkan data kolom.\n"); try{ System.out.println("\n kolom 1"); for(int a=0;a<=data.length;a++){ System.out.println(" "+data[a][0]); } } catch(ArrayIndexOutOfBoundsException ae){ } try{ System.out.println("\n kolom 2"); for(int b=0;b<=data.length;b++){ System.out.print(" "+data[b][1]); System.out.println(""); } } catch(ArrayIndexOutOfBoundsException ae){ } try{ System.out.println("\n kolom 3"); for(int c=0;c<=data.length;c++){ System.out.print(" "+data[c][2]); System.out.println(""); } } catch(ArrayIndexOutOfBoundsException ae){ } break; case 3: System.out.println("\n Tampilkan data baris."); try{ System.out.println("\n baris 1"); for(int a=0;a<=data.length;a++){ System.out.print(" "+data[0][a]); } } catch(ArrayIndexOutOfBoundsException ae){ } try{ System.out.println("\n\n baris 2"); for(int b=0;b<=data.length;b++){ System.out.print(" "+data[1][b]); } } catch(ArrayIndexOutOfBoundsException ae){ } try{ System.out.println("\n\n baris 3"); for(int c=0;c<=data.length;c++){ System.out.print(" "+data[2][c]); } } catch(ArrayIndexOutOfBoundsException ae){ } try{ System.out.println("\n\n baris 4"); for(int d=0;d<=data.length;d++){ System.out.print(" "+data[3][d]); } } catch(ArrayIndexOutOfBoundsException ae){ } break; case 4: System.out.println(" Tampilan Unik \n"); // Tampilkan : Gajah Putih Abu-abu Pemakan Daging dan rumput. System.out.println(data[0][0]+" "+data[1][1]+" "+data[0][1]+" memakan "+data[2][2]+" dan "+data[0][2]+"."); break; default: System.out.println("## piliihan yang anda masukkan salah##"); GOTO akhir; break; } } while(x>=1 &&x<=4); akhir: System.out.println("## Terima kasih ##"); } }


g terlalu panjang kan (nulis sampai puyeng) hehehehe.....
jangan lupa tulis komentarnya yah....

No Response to "array 2 dmensi"

Leave A Reply

cara masukin comment, dibawah form ini ada pilihan "comment as" klik, dan pilih NAME/URL isi nama trus url blog kalian, klo blm punya blog, alamat URL dikosongi aj. trus isi comment dan klik "post comment"

Artikel update lainnya

Comunity Link :