Array


Array
Array adalah kumpulan data yang memiliki tipe yang sama.
•Terdapat 3 langkah untuk membuat array:
– Mendeklarasikan variabel array
– Memcreate array beserta ukurannya.
– Memberikan sebuah nilai pada setiap element array.
contoh pembuatan array dalam java :
  • Array 1 dimensi
– tipeData[] namaVariabel [= new tipeData[jumlahElemen] ];
  1. int[] angka;
  2. int[] angka = new int[5];
  3. int[] angka = {5, 3, 23, 99, 2};
  • Array 2 dimensi
-tipeData[][] nama_variabel[=new tipeData[ukuran_1] [ukuran_2]];
  1. double uas[]   = {80,70,70,60,70,80,70,60,60,70,70,70,70,75,65};
saya sertakan contoh source code perhitungan nilai 15 siswa input secara statis :
==============================================================
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package nilaiakhir;/**
*
* @author tiano89
*/
public class NilaiAkhir {/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String nama[] = {“Seftian”,”Akasa”,”Badri”,”Budi Santosa”,”Adiatma”,”Ari duli”,”momos”,”momon”,”mimin”,”usepat”,”Saepudin”,”Makroni”,”Burger”,”Cuanki”,”Gehu Pedas”};
double uts[] = {89,98,77,67,76,88,73,66,65,77,80,80,80,85,55},tugas[] = {70,70,70,70,70,70,70,70,70,70,70,70,70,70,70};
double uas[] = {80,70,70,60,70,80,70,60,60,70,70,70,70,75,65};
double nilai[] = new double[15];
String index;
for (int i=0; i= 80)
{
index = “A”;
}
else if(nilai[i]>= 70 && nilai[i]< 80) { index = “B”; } else if(nilai[i]>= 60 && nilai[i]< 70) { index = “C”; } else if(nilai[i]>= 50 && nilai[i]< 60)
{
index = “D”;
}
else
{
index = “E”;
}System.out.println(“Nilai”+nama[i]+” = Uts “+uts[i]+ “, Uas “+uas[i]+”, Tugas “+tugas[i]+” = Hasil “+nilai[i]+” Dengan begitu indexnya = “+index);
}
}
}===================================================================

input :

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s