Pages

Subscribe:

Ads 468x60px

♪ ♥ Get Paid Daily - The Best Sites PTC ♥ ♪
DonkeyMails.com: No Minimum Payout
AyuWage Services - Get Paid to Visits Sites and Complete Surveys

Senin, 16 Juli 2012

Mengurutkan Elemen Array

Mengurutkan Elemen Array

public class DataSort {
public static void main(String[] args) {
int[] data = new int[5];
for(int index=0; index<data.length; index++) {
data[index] = (int) (Math.random()*100);
}
System.out.println(“Data awal”);
System.out.println(“———”);
for(int index=0; index<data.length; index++) {
System.out.println(“data” + “[" + index + "]” + ” = ” + data[index]);
}
System.out.println();
for(int x=0; x<data.length-1; x++) {
for(int y=x+1; y<data.length; y++){
if(data[x] > data[y]) {
int temp = data[x];
data[x] = data[y];
data[y] = temp;
}
}
}
System.out.println(“Data setelah diurutkan”);
System.out.println(“———————-”);
for(int z=0; z<data.length; z++){
System.out.println(“data” + “[" + z + "]” + ” = ” + data[z]);
}
System.out.println();
}
}
output program:
Data awal
---------
data[0] = 7
data[1] = 89
data[2] = 47
data[3] = 89
data[4] = 6
Data setelah diurutkan
----------------------
data[0] = 6
data[1] = 7
data[2] = 47
data[3] = 89
data[4] = 89

0 komentar:

Posting Komentar

Please Give Your Feedback Or Message.
Thank You!!?

Unique 1:1 Traffic Exchange

♪ ♥ Ma liste de blogs ♥ ♪

♪ ♥ Please Votes! Thanks. ♪ ♥
×