Mesran

Hanya ingin berbagi kebaikan dan mendapatkan kebaikan yang lain.

Array Pada Java

Array merupakan suatu kumpulan data yang sejenis yang terdapat di dalam sebuah variabel.

Syntax  :    typedata   variabel[] ;
Variabel = new typedata[jumlahdata] ;

Contoh :
int nilai[] ;
nilai = new int[10] ;

String Nama[] ;
Nama =  new String[10] ;

Contoh Program :
lat14.java

public class lat14{
public static void main(String Arg[]) {

int i=0 ; int total=0 ; double rata=0 ;
int nilai[] ;
nilai = new int[10] ;
nilai[0] = 67 ;    nilai[1] = 70 ;
nilai[2] = 80 ;    nilai[3] = 91 ;
nilai[4] = 100;   nilai[5] = 75 ;
nilai[6] = 47 ;    nilai[7] = 63 ;
nilai[8] = 70 ;    nilai[9] = 30 ;
do {
System.out.println(“Nilai  :” + nilai[i] ) ;
total = total + nilai[i] ;
i++ ;
} while (i<=9) ;

rata = total/9 ;
System.out.println(“Nilai Rata Rata :” + rata ) ;

}
}

Hasilnya seperti gambar di bawah ini :

Filed under: Java 2 SE,

Terima kasih telah memberikan komentar anda.

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

Archives Per Tahun

Sponsored

C&C Online Shop

Blog Stats

  • 355,762 sejak 12 Jan 2011

User’s Online


My Music

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 223 other followers

April 2011
M T W T F S S
« Mar   May »
 123
45678910
11121314151617
18192021222324
252627282930  
%d bloggers like this: