New Entri

Sabtu, 03 Juli 2010

Contoh Program JAVA Mengurutkan Data Selection Sort

//Mengurutkan Data

public class tugas2

{

public static void main (String[]args)

{

int[] angka = new int[7];

//inisialisasi array

for (int i=0;i

angka[i] = (int)(Math.random()*100);

//Menampilkan Data Awal

System.out.println("Data sebelum disortir");

System.out.println("----------------------");

for (int i=0;i

System.out.println(angka[i]+ " ");

//Proses sortir dengan Selection sort

for (int x=0;x

for (int y=x+1;y

if (angka[x]>angka[y])

{

int bantu=angka[x];

angka[x]=angka[y];

angka[y]=bantu;

}

//Menampilkan data

System.out.println("\n\nData Setelah "+"sortir");

System.out.println("---------------------------");

for (int i=0;i

System.out.print(angka[i]+" ");

System.out.println();

}

}

Output ;










0 komentar:

Posting Komentar